[go: up one dir, main page]

0% found this document useful (0 votes)
37 views24 pages

JUnit 5 Test Scripts Guide

This document provides an overview and tutorial on writing JUnit 5 test scripts. It covers JUnit annotations for preconditions, test methods, and postconditions in both JUnit 4 and JUnit 5. It also discusses adding JUnit 5 dependencies, writing JUnit 5 test scripts, reviewing assertions, converting from JUnit 4 to JUnit 5, and running tests in Jupiter. The tutorial aims to teach readers how to execute, write, and structure tests in JUnit 5.

Uploaded by

Dilip N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views24 pages

JUnit 5 Test Scripts Guide

This document provides an overview and tutorial on writing JUnit 5 test scripts. It covers JUnit annotations for preconditions, test methods, and postconditions in both JUnit 4 and JUnit 5. It also discusses adding JUnit 5 dependencies, writing JUnit 5 test scripts, reviewing assertions, converting from JUnit 4 to JUnit 5, and running tests in Jupiter. The tutorial aims to teach readers how to execute, write, and structure tests in JUnit 5.

Uploaded by

Dilip N
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

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

You might also like