Skip to content

mohamedhamady/junit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Junit 4 vs Junit 5

Architecture

Junit 4

  • Monolithic : Everything is bundled into a single jar junit4.jar

Junit 5:

  • Platform

     - Internal common library/utilities of JUnit
     - Public API for test engines
     - Public API for configuring and launching test plans.
     - Runner and annotations for configuring and executing tests.
    
  • Jupiter

     - New junit annotations and TestEngine implementation to run tests written with these annotations.
     - Migration support from JUnit 4 to JUnit Jupiter
    
  • Vintage

     - support running JUnit 3 and JUnit 4 written tests on the JUnit 5 platform.
    

"Junit 5 component diagram"

Annotations

Features JUnit 5 JUnit 4
Declares a test method @Test @Test
Denotes that the annotated method will be executed before all test methods in the current class @BeforeAll @ BeforeClass
Denotes that the annotated method will be executed after all test methods in the current class @AfterAll @AfterClass
Denotes that the annotated method will be executed before each test method @BeforeEach @Before
Denotes that the annotated method will be executed after each test method @AfterEach @After
Disable a test method or a test class @Disable @Ignore
Denotes a method is a test factory for dynamic tests in JUnit 5 @TestFactory N/A
Denotes that the annotated class is a nested, non-static test class @Nested N/A
Declare tags for filtering tests @Tag @Category
Register custom extensions in JUnit 5 @ExtendWith N/A

Assertions

JUnit 5 JUnit 4
fail fail
assertTrue assertTrue
N/A assertThat
assertSame assertSame
assertNull assertNull
assertNotSame assertNotSame
assertNotEquals assertNotEquals
assertNotNull assertNotNull
assertFalse assertFalse
assertEquals assertEquals
assertArrayEquals assertArrayEquals
assertAll N/A
assertThrows N/A
assertTimeout N/A
assertTimeoutPreemptively N/A

Junit 5 Example

Junit 4 Example

Assumptions

JUnit 5 JUnit 4
assumeFalse assumeFalse
assumeNoException
assumeNotNull
assumeThat assumeThat
assumeTrue assumeTrue

Junit 5 Example

Junit 4 Example

Tagging and Filtering

Junit 5 Example

Junit 4 Example

Nested Tests

Junit 5 Example

Junit 4 Example

Dependency Injection for Constructors and Methods

Junit 5 Example-1 Junit 5 Example-2 Junit 5 Example-3

Test Interfaces and Default Methods

Junit 5 Example-1 Junit 5 Example-2

Repeated Tests

Junit 5 Example

Junit 4 Example

Parameterized Tests

Junit 5 Example

Junit 4 Example-1 Junit 4 Example-2 Junit 4 Example-3

Extension Model

Junit 5 Example

Junit 4 Example-1 Junit 4 Example-2

Migration

See @EnableRuleMigrationSupport

Junit 5 Example

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages