Summary

This section provides a detailed insight of how JUnit 5 can be used in conjunction with third-party frameworks, libraries, and platforms. Thanks to the Jupiter extension model, developers can create extensions which allows seamless integration with external frameworks to JUnit 5. First, we have seen the MockitoExtension, an extension provided by the JUnit 5 team to use Mockito (a notorious mock framework for Java) in Jupiter tests. Then, we have used the SpringExtension, which is the official extension provided in the version 5 of the Spring Framework. This extension integrates Spring into the JUnit 5 programming model. This way, we are able to use Spring’s application contexts (that is, the Spring’s DI container) in our tests.

We have also reviewed the SeleniumExtension implemented by selenium-jupiter, an open source project providing a JUnit 5 extension for Selenium WebDriver (testing framework for web applications). Thank to thins extension, we can use different browsers to interact automatically with web applications and emulated mobile devices (using Appium). Then, we have seen the CucumberExtension, allows to specify JUnit 5 acceptance tests following a BDD style using the Gherkin language. Finally, we have seen how the open source JUnit5-Docker extension can be used to start Docker containers (downloading the image from Docker Hub) before the execution of our JUnit 5 tests.

Moreover, we discovered that the extension model is not the only way of interacting with external technologies by JUnit tests. For example, in order to run Jupiter tests in an Android project, we can use the android-junit5 plugin. On the other hand, even though there is no custom extension for assessing REST services using JUnit 5, the integration with such libraries is strait forward: we simply need to include the proper dependency in our project and use it in our tests (for example, REST Assured, Spring, or WireMock).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.182.159