Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Automated Testing for Digital Experiences Using JUnit 5

228 views

Published on

MIKE KOLENO CTO, SOLSTICE
JUnit 5 is launching this fall and will undoubtedly move the needle for automated testing. Simultaneously, the demands of digital continue to grow and place a greater importance on automated testing for backend systems. Join Mike Koleno for a discussion where he will highlight the new features of JUnit 5, including Lambda support, dynamic and parameterized tests, and advances in integration testing. Mike will demonstrate the new testing features through the lens of a conversational UX experience.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Automated Testing for Digital Experiences Using JUnit 5

  1. 1. © 2016 Pivotal !2 Automated Testing for Digital Experiences Mike Koleno, CTO, Solstice With JUnit 5
  2. 2. PROPRIETARY & CONFIDENTIAL 3 solstice.com ABOUT ME • My name is Mike Koleno • CTO & Head of Enterprise Cloud Computing at Solstice • Enterprise developer & architect for 15+ years • Consulted on behalf of 40+ Fortune 1000 enterprises
  3. 3. 4 PROPRIETARY & CONFIDENTIAL solstice.com Reimagine Digital Customer Experiences Design and Build New Digital Products Help with Digital Operations 1 2 3 DIGITAL INNOVATION FIRM
  4. 4. PROPRIETARY & CONFIDENTIAL 5 solstice.com AGENDA • It’s All About the Tests • Where we’ve been - through the lens of Java/Spring & JUnit 4 • Where we’re going - JUnit 5 • Slackbot demo
  5. 5. PROPRIETARY & CONFIDENTIAL 6 solstice.com IT’S ALL ABOUT THE TESTS Tests Have Expanded Unit Tests have grown into Integration Tests, Functional Tests and System Tests Dev & Build Tools Tools are constantly adding new features for writing/running tests TDD & CI/CD Modern Software Engineering techniques highly value automated tests
  6. 6. 7 PROPRIETARY & CONFIDENTIAL solstice.com 2006 - JUnit 4 introduced 2007 - First iPhone released 2014 - Java 8 released 2013 - Slack launched 2008 - first GitHub repo
  7. 7. PROPRIETARY & CONFIDENTIAL 8 solstice.com JUNIT 4 - THE GAPS Any Day Now… JUnit 4 built on Java 5, unable to make use of modern language features Developer Friction Rules, Runner restrictions, etc. Tight Coupling Test Writing API coupled with Test Discovery & Execution API’s
  8. 8. JUNIT 5 9 PROPRIETARY & CONFIDENTIAL solstice.com
  9. 9. PROPRIETARY & CONFIDENTIAL 10 solstice.com MODULARIZING JUNIT = JUnit Platform API for Dev & Build Tools Test discovery and execution JUnit Jupiter+ Contains the developer API’s to write tests JUnit Vintage+ Ability to run legacy tests (JUnit 3 & JUnit 4) ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  10. 10. PROPRIETARY & CONFIDENTIAL 11 solstice.com LAMBDA SUPPORT @Test void lambaTest() {    List<Integer> numbers = Arrays.asList(1, 2, 3);    assertTrue(numbers        .stream()        .mapToInt(i -> i)        .sum() > 5, () -> "Sum should be greater than 5"); } ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  11. 11. PROPRIETARY & CONFIDENTIAL 12 solstice.com EXTENSION MODEL • Allows developers to hook into different test life cycle callback events via an extension • BeforeAllCallback, BeforeEachCallback, BeforeTestExecutionCallback • AfterTestExecutionCallback, AfterEachCallback, AfterAllCallback ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  12. 12. PROPRIETARY & CONFIDENTIAL 13 solstice.com EXTENSION MODEL (CONT) ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  13. 13. PROPRIETARY & CONFIDENTIAL 14 solstice.com PARAMETERS @ExtendWith(MockedSystemExtension.class) public class SystemTest { @Test public void test(final MockedSystem mockedSystem) { final Response response = mockedSystem.target().request().get(); assertEquals(response.getStatusInfo().getFamily(), Response.Status.Family.SUCCESSFUL, () -> "status code is not 2xx"); assertEquals(response.getHeaderString("X-Hello"), "World", () -> "header 'X-Hello' not correct"); } } • Allows developers to pass parameters into tests ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  14. 14. PROPRIETARY & CONFIDENTIAL 15 solstice.com PARAMETERS (CONT) public class MockedSystemExtension implements ParameterResolver { @Override public boolean supports(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException { return parameterContext.getParameter().getType().isAssignableFrom(MockedSystem.class); } @Override public Object resolve(final ParameterContext parameterContext, final ExtensionContext extensionContext) throws ParameterResolutionException { final MockedSystem mockedSystem = new MockedSystem(); return mockedSystem; } } ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  15. 15. @TestFactory default Collection<DynamicTest> dynamicTestsFromCollection() { return Arrays.asList( dynamicTest("1st dynamic test in test interface", () -> assertTrue(true)), dynamicTest("2nd dynamic test in test interface", () -> assertEquals(4, 2 * 2)) ); } PROPRIETARY & CONFIDENTIAL 16 solstice.com DYNAMIC TESTS ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  16. 16. PROPRIETARY & CONFIDENTIAL 17 solstice.com NEW TEST CONVENTIONS PARAMETERIZED TESTS @ParameterizedTest @ValueSource(ints = { 1, 2, 3 }) void testWithValueSource(int argument) { assertNotNull(argument); } @RepeatedTest(10) void repeatedTest() { // ... } REPEATED TESTS ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  17. 17. PROPRIETARY & CONFIDENTIAL 18 solstice.com OTHER CHANGES - DISABLING TESTS The @Disabled annotation was added in order to disable test cases and individual tests ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  18. 18. PROPRIETARY & CONFIDENTIAL 19 solstice.com OTHER CHANGES - DISPLAY NAME The @DisplayName annotation can be used to provide better description names to your tests ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  19. 19. PROPRIETARY & CONFIDENTIAL 20 solstice.com OTHER CHANGES - @TAG @Tags have replaced @Categories in order to group and filter tests ARCHITECTURE EXTENSIBILITY NEW TESTS ANNOTATIONS
  20. 20. PROPRIETARY & CONFIDENTIAL 21 solstice.com SLACKBOT DEMO ARCHITECTURE
  21. 21. STAY IN TOUCH 22 PROPRIETARY & CONFIDENTIAL solstice.com Mike Koleno CTO mkoleno@solstice.com solstice.com Slackbot demo: bit.ly/2r8Ctlf

×