Posted in Automation Testing Tool, Selenium

JUnit 4 vs JUnit 5:An Overview

Junit5

JUnit5, the Next Generation Junit. A Regression Testing Framework used by developers and tester to implement unit and functional testing in Java and Selenium, to accelerate programming speed and increase the quality of code. JUnit Framework can be easily integrated with either of the following –Eclipse, Ant, Maven. Junit5 introduces New Assert and Annotations to test your code more efficiently.

Junit5 requires Java 8 and above Java version and some useful annotations are:

@ParameterizedTest: Denotes that a method is a parameterized test. Such methods are inherited unless they are overridden.

 

@RepeatedTest: Denotes that a method is a test template for a repeated test. Such methods are inherited unless they are overridden.

@DisplayName: Declares a custom display name for the test class or test method. Such annotations are not inherited.

@BeforeEach: Denotes that the annotated method should be execute before each @Test,@RepeatedTest, @ParameteizedTest or @Test Factory method in the current class; analogous to JUnit 4’s @Before. Such methods are inherited unless they are overridden.

@AfterEach: Denotes that the annotated method should be executed after  @Test

@AfterAll:Denotes that the annotated method should be executed after @RepeatedTest@ParameterizedTest, and @TestFactory methods in the current class; analogous to JUnit 4’s @AfterClass. Such methods are inherited (unless they are hidden or overridden) and must be static (unless the “per-class” test instance lifecycle is used).

@Tag: Used to declare tags for filtering tests, either at the class or method level; analogous to test groups in TestNG or Categories in JUnit 4. Such annotations are inherited at the class level but not at the method level.

Screen Shot 2018-08-07 at 4.12.22 PM

Asserts in Junit:

Screen Shot 2018-08-07 at 4.13.42 PM

For More Information you may visit JUnit Official site Click here and For comparison with JUnit 4 you may visit click here

Reference:https://junit.org/junit5/docs/current/user-guide/

Author:

My name is Abhishek Roy and i am a Senior Software Test Engineer having about 4 years of experience in the field of Automation testing .I have passion toward Automation testing and love to explore new things related to automation.I having experience in Selenium,Java,cucumber,Jmeter maven,TestNg,Katalon Studio and Junit.

Leave a comment