Date post: | 28-Jan-2018 |
Category: |
Software |
Upload: | kostadin-golev |
View: | 322 times |
Download: | 1 times |
kgolev.com@kotseto
Why JUnit 5? Where Is It? Writing Tests Platform For The JVM Running Along JUnit 3 & 4 Important New Features IDE & Tool Support
kgolev.com@kotseto
4.12-beta-1:
org.junit.ComparisonFailure: expected: null<null> but was: null<null>
4.11:
org.junit.ComparisonFailure: expected:<[1]L> but was:<[2]L>
assertEquals(1, 2)
kgolev.com@kotseto
Extension mechanism
Runner @RunWith(SpringJUnit4ClassRunner.class)
Rule @Rule ExpectedException thrown = none()
kgolev.com@kotseto
Why JUnit 5?
Where Is It? Writing Tests Platform For The JVM Running Along JUnit 3 & 4 Important New Features IDE & Tool Support
kgolev.com@kotseto
Why JUnit 5? Where Is It?
Writing Tests Platform For The JVM Running Along JUnit 3 & 4 Important New Features IDE & Tool Support
kgolev.com@kotseto
@Test void exception() { RuntimeException thrown = assertThrows(RuntimeException.class, () -> library.throwRuntimeException("message") );
assertEquals("message", thrown.getMessage()); }
kgolev.com@kotseto
Why JUnit 5? Where Is It? Writing Tests
Platform For The JVM Running Along JUnit 3 & 4 Important New Features IDE & Tool Support
kgolev.com@kotseto
Launcher
<<interface>> Engine
Engine Impl
Jupiter API
implements
JUnit Platform
JUnit Jupiter
kgolev.com@kotseto
<<interface>> Engine
Engine Implementation
implements
JUnit Platform
JUnit Jupiter
kgolev.com@kotseto
Why JUnit 5? Where Is It? Writing Tests Platform For The JVM
Running Along JUnit 3&4 Important New Features IDE & Tool Support
kgolev.com@kotseto
Launcher
<<interface>> Engine
Vintage Engine Impl
JUnit 3&4 API
implements
JUnit Platform
JUnit Vintage
kgolev.com@kotseto
Platform for the JVMDevelopers already started implementing their own
engines, reusing JUnit5 tool integration
kgolev.com@kotseto
Why JUnit 5? Where Is It? Writing Tests Platform For The JVM Running Along JUnit 3 & 4
Important New Features IDE & Tool Support
kgolev.com@kotseto
assertEquals(1, 2); assertEquals("String", "Another String");
org.opentest4j.AssertionFailedError:
Expected :1 Actual :2
kgolev.com@kotseto
assertAll( () -> assertEquals(1, 2), () -> assertEquals("String", “Another String") )
org.opentest4j.MultipleFailuresError: Multiple Failures (2 failures)
expected: <1> but was: <2> expected: <String> but was: <Another String>
kgolev.com@kotseto
@ExtendWith(SpringExtension.class) @ExtendWith(MockitoExtension.class) public class SpringTest {
@Autowired SpringComponent component; @Mock Dependency mocked;
kgolev.com@kotseto
class ParameterInTestMethods {
@Test @ExtendWith(MockitoExtension.class) void test(@Mock Dependency mocked) { … }
kgolev.com@kotseto
public class MockitoExtension implements TestInstancePostProcessor {
@Override public void postProcessTestInstance( Object testInstance, ExtensionContext context) { MockitoAnnotations.initMocks(testInstance); } }
kgolev.com@kotseto
Not many extensions yeta few unofficial ones
Spring and Mockito support in next releases
kgolev.com@kotseto
public class Library {
private Books books;
public Library(Books books) { this.books = books; }
public void addBook(Book book) { // do something with books
} }
kgolev.com@kotseto
@Test void whenBookExistsThenIncrementAmount() {}
@Test void whenBookExistsThenCheckAmountMoreThenN() {}
@Test void whenBookDoesNotExistThenCreateBook() {}
@Test void whenBookDoesNotExistThenSendNewBookNotification() {}
kgolev.com@kotseto
@DisplayName("Book is added to library") class BookAddedTest {
@DisplayName("when book exists") @Nested class whenBookExists {
@DisplayName("amount++") @Test void incrementAmount() {}
@DisplayName("check amount > limit") @Test void checkAmountMoreThenLimit() {} }
. . . }
kgolev.com@kotseto
@Test void strIsLessThenTenChar() { int value = "str".length(); assertTrue(value < 10); }
@Test void StringIsLessThenTenChar() { int value = "String".length(); assertTrue(value < 10); }
kgolev.com@kotseto
@ValueSource(strings = {“str”, “String”}) @ValueSource(ints = {1, 3, 7, 9}) @EnumSource(SomeEnum.class) @CsvSource({"1, 1", "2, 4", "4, 16”}) @CsvFileSource(resources=“testData.csv”)
kgolev.com@kotseto
@MethodSource(names=“stringAndIntProvider")
static Stream<Arguments> stringAndIntProvider() { return Stream.of( ObjectArrayArguments.create("foo", 3), ObjectArrayArguments.create("foobar", 6) ); }
kgolev.com@kotseto
Why JUnit 5? Where Is It? Writing Tests Platform For The JVM Running Along JUnit 3 & 4 Important New Features
IDE & Tool Support
kgolev.com@kotseto
Supports latest release candidate
Support in Oxygen 4.7 BETA Official support target 4.7.1
ETA: September 2017