24-Testing Flashcards

1
Q

From what Spring version JUnit 5 becomes the default JUnit version?

A

Spring Boot 2.2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Components in JUnit 5

A

Platform
Jupiter: extension model & extensions
Vintage: support JUnit 3, 4

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the big difference between JUnit 4 and 5? Give an example

A

The big difference between 4 and 5 is the extension framework. Allows multiple frameworks to customize tests at the same time. For example to run Spring-based tests and use the test support of a mocking library too.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

New annotations in JUnit 5

A

@DisplayName - Displays the name of each test on the console when it is run
@Nested - Multiple nested tests can be defined in a single test
@ParameterizedTest - Run the same test multiple times with different arguments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to ignore a test in JUnit 5?

A

@Disabled

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is @ContextConfiguration used for?

A

configration for TestContext

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Jar file of spring test framework

A

spring-test.jar

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What framework defines application context for Spring tests?

A

TestContext framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to define a test class with SpringExtension?

A
@ExtendWith(SpringExtension.class) // mandatory
@ContextConfiguration(classes={SystemTestConfig.class}) // mandatory
public class TransferServiceTests {}

Note: shortcut @SpringJUnitConfig(SystemTestConfig.class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
In which env does the following definition works?
void hello(@Autowired TransferService ts) {}
A

Only in test we can use @Autowired for argument

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens if using @SpringJUnitConfig without configuration class?

A

Spring will search static @Configuration embedded in test class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

About @TestPropertySource

A

Custom properties just for testing
Has higher precedence than sources
example:
@SpringJUnitConfig(SystemTestConfig.class)
@TestPropertySource(properties = { “username=foo”, “password=bar” },
locations = “classpath:/transfer-test.properties”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Write a Spring test with JUnit4

A
@RunWith(SpringRunner.class)
@ContextConfiguration(SystemTestConfig.class)
public class TransferServiceTests {}

Note: can use either SpringRunner or SpringJUnit4ClassRunner

How well did you know this?
1
Not at all
2
3
4
5
Perfectly