gradle:
1 2 3 4 5 |
apply plugin: 'java' dependencies { testCompile 'junit:junit:4.12' } |
maven:
1 2 3 4 5 |
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> |
Expected Exceptions Test
1 2 3 4 |
@Test(expected = UnsupportedOperationException.class) public void reverseList() { list.getReverseList(); } |
@RunWith BlockJUnit4ClassRunner – default junit runner SpringJUnit4ClassRunner allows you to use dependency injection in test classes or to create transactional test methods. MockitoJUnitRunner for automatic mock initialization. Suite Parameterized Parameters class
1 2 3 4 5 6 7 8 9 |
@RunWith(value = Parameterized.class) public class ParametersTest { // ... @Parameters public static Collection<Object[]> data() { @Test //will be run Collection.size times public void testData(){ } |
JUnit 5 – @ExtendWith
1 |
@RunWith(SpringJUnit4ClassRunner.class) |
replace with
1 |
@ExtendWith(SpringExtension.class) |
@Rule
1 |
@Rule public ExpectedException exception = ExpectedException.none(); |
1 |
@Rule public TemporaryFolder folder = new TemporaryFolder(); |
or your custom rule: […]