junit 5 alpha

19
JUnit 5 Alpha

Upload: jaran-nilsen

Post on 16-Feb-2017

84 views

Category:

Software


0 download

TRANSCRIPT

Page 1: JUnit 5 Alpha

JUnit 5 Alpha

Page 2: JUnit 5 Alpha

• A refreshing update to the existing JUnit framework

Page 3: JUnit 5 Alpha

• No groundbreaking new features or changes, but finally taking advantage of Java 8

Page 4: JUnit 5 Alpha

• No conflict with existing JUnit 4 tests

• The JUnit 5 API has been placed under the org.junit.gen5 package

Page 5: JUnit 5 Alpha

• JUnit 5 tests may be run along side JUnit 4 tests, in your IDE

• Use @RunWith(JUnit5.class) and your IDE should pick them up just like any other JUnit tests

Page 6: JUnit 5 Alpha

• Test classes and methods no longer have to be public, but can be package private

Page 7: JUnit 5 Alpha

Familiar annotations• @Test

• @Before

• @After

• @BeforeAll

• @AfterAll

Page 8: JUnit 5 Alpha

Name your tests

• @DisplayName(“More readable name”)

Page 9: JUnit 5 Alpha

Disabled tests

• @Disabled instead of @Ignore

Page 10: JUnit 5 Alpha

Assertions

• assertEquals now takes optional assertion message as last parameter

• assertAll enables grouped assertions

• Better exception testing via expectThrows and assertThrows assertion methods

Page 11: JUnit 5 Alpha

Assumptions• assumeTrue

• assumingThat

Page 12: JUnit 5 Alpha

Tags

• Similar to categories, but extended beyond @Category

• @Tag(“web-tests”)

Page 13: JUnit 5 Alpha

Nested tests

• Nest test classes for better grouping and organisation

• Note that @BeforeAll and @AfterAll does not work on the nested classes

Page 14: JUnit 5 Alpha

Constructor and method parameters

• JUnit 5 allows constructors and methods to have parameters

• ParameterResolver defines an API for resolving these parameters at runtime and provide them to the tests

Page 15: JUnit 5 Alpha

Composed annotations• JUnit 5 annotations can be used as meta-

annotations, meaning you can compose your own annotations based on these annotations

Page 16: JUnit 5 Alpha

Extension model• Good bye Runner, Rule and ClassRule

• Hello, @ExtendWith!

• ContainerExecutionCondition and TestExecutionCondition evaluates whether or not to execute a test class, or single test

Page 17: JUnit 5 Alpha

Let’s see this in action!

Page 18: JUnit 5 Alpha

More information:

junit.org/junit5

Page 19: JUnit 5 Alpha

Thank you!twitter.com/jaranflaath [email protected]

Image CC BY-SA 4.0 Ashashyou (https://commons.wikimedia.org/wiki/User:Ashashyou)