JUNIT5 General Introduction __junit5

Source: Internet
Author: User
What's JUnit5?The official website describes the following: JUnit 5 is the next generation of JUnit. The goal is to create a up-to-date foundation for developer-side testing on the JVM. This is includes focusing on Java 8 and above, as as and as enabling many different of styles. JUnit 5 is the "result of" JUnit Lambda and its crowdfunding campaign on Indiegogo.
The main thing is that Junit5 based on Java8 and above, the implementation of a number of Java8 features such as lambda expression and interface default method, etc. JUnit5 is divided into the following three modules 1. JUnit Platform the responsibilities of JUnit platform Load test framework into the JVM defines the Testengine API to extend the test framework to provide Console launcher to support command line and maven and Gradle Plug-ins Key Categories: Testengine, Launcher 2. JUnit JupiterProvides a JUNIT5 programming model and extension model that provides a testengine implementation (Jupitertestengine) to run Jupiter based testing 3.Junit VintageUsed to run JUnit low version of the test case to ensure backward compatibility JUnit5 's annotationJUnit5 all the annotation are under the Org.junit.jupiter.api bag. 1. Annotation equivalent to JUNIT4 @Disabled = = @Ignore @BeforeEach = = @Before, @AfterEach = = @After
@BeforeAll = = @BeforeClass, @AfterAll = = @AfterClass 2. JUnit5 added Annotations1. @DisplayName: Set up the test class or test method of the display content, when the final results are printed out can be seen, the content can be text or even emoji
@Test
    @DisplayName ("╯°-°) ╯")
    void Testwithdisplaynamecontainingemoji () {
    }

2. @TestInstance: Defined above the class, to control whether the instance of the test class is a singleton, that is, whether the instance is shared by all test methods of the class, that is, the Per_class and Per_method two modes, defined as
    @Target (Elementtype.type)
    @Retention (retentionpolicy.runtime)
    @Inherited
    @Documented
    @API ( Status = stable, since = "5.0") public
    @interface Testinstance

3. @ExtendWith: The expansion of the test class, based on the Java SPI mechanism, interface for extension, as an alternative to @runwith, the typical implementation has springextension, mockitoextension
4. @ParameterizedTest: Parametric testing, indicating that the test method can have parameters
@ParameterizedTest
    @ValueSource (strings = {"Hello", "World"})
    void Testwithstringparameter (String argument) {
        assertnotnull (argument);
    }

5. @Tag: Label the class or method, used for filtering, similar to the concept of categories in JUNIT4, can be defined annotation to achieve the effect of replication @tag
@Target ({elementtype.type, elementtype.method})
    @Retention (retentionpolicy.runtime)
    @Tag ("Fast") Public
    @interface Fast {
    }

















Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.