Write JUnit 5
Test Scripts
Rex Jones II
JUnit 5
Tutorial Playlist
1. How To Execute JUnit 4 With JUnit 5 8. Tagging & Filtering In JUnit 5
2. How To Write JUnit 5 Test Scripts 9. Execute Packages & Classes
3. How To Run JUnit Tests In Jupiter 10. Nested Tests In JUnit 5
4. sleep() Method With Selenium & Java 11. How To Use Extension In JUnit 5
5. Timeouts In JUnit 5 12. How To Compare PDF Files In Java
6. WebDriverWait In Selenium & Java 13. How To Use Mockito With JUnit 5
7. Minimize Browsers In Selenium 14. How To Mock Arrays.asList()Rex Jones II
JUnit 5
What You Will Learn
1. JUnit 5 & JUnit 4 Annotations
2. Add JUnit 5 Dependencies
3. Write JUnit 5 Test Scripts
4. Review & Write Assertions
5. Convert Test Script From JUnit 4 To JUnit 5
Rex Jones II
JUnit
Annotations
Rex Jones II
JUnit
Annotations
Description JUnit 4
Executes before all test methods in the current class @BeforeClass
Executes after all test methods in the current class @AfterClass
Executes before each test method indicated by @Test @Before
Executes after each test method indicated by @Test @After
Declares a test method @Test
Rex Jones II
JUnit
Annotations
Description JUnit 4 JUnit 5
Executes before all test methods in the current class @BeforeClass @BeforeAll
Executes after all test methods in the current class @AfterClass @AfterAll
Executes before each test method indicated by @Test @Before @BeforeEach
Executes after each test method indicated by @Test @After @AfterEach
Declares a test method @Test @Test
Rex Jones II
JUnit 5
Annotations
▪ Pre-Condition(s)
❑ @BeforeAll
❑ @BeforeEach
▪ Condition(s) - @Test
▪ Post-Condition(s)
❑ @AfterEach
❑ @AfterAll
Rex Jones II
Add JUnit 5
Dependencies
Rex Jones II
Rex Jones II
Write JUnit 5
Test Scripts
Rex Jones II
Rex Jones II
Rex Jones II
Rex Jones II
Rex Jones II
Review & Write
Assertions
Rex Jones II
JUnit 5 Assertion
Methods
▪ assertTrue – verifies a condition is true
▪ assertFalse – verifies a condition is false
▪ assertSame – verifies that 2 objects refer to the same object
▪ assertNotSame – verifies that 2 objects do not refer to the same object
▪ assertNotNull – verifies that an object is not null
▪ assertEquals – verifies actual and expected results are equal
Rex Jones II
JUnit 4 Assert
&
JUnit 5 Assertions
// JUnit 4 Syntax
Assert.assertEquals(“String Message”, expected, actual)
// JUnit 5 Syntax
Assertions.assertEquals(expected, actual, “String Message”)
Rex Jones II
Rex Jones II
Rex Jones II
Recap
Rex Jones II
Convert Test Script
From JUnit 4
To JUnit 5
Rex Jones II
Run JUnit Tests
In Jupiter
Rex Jones II
Yearning to learn more?
Follow us at
https://www.lambdatest.com/blog
https://community.lambdatest.com
Rex Jones II
Earn resume-worthy LambdaTest
Selenium certifications
https://www.lambdatest.com/certifications
Get Educated
Get Recognized
Rex Jones II