Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create test suite as in junit 4 using Junit5

as we are upgrading to junit5 from junit4 for unit testing purpose, i couldn't able to find solution to creating a test suite in junit5 like in junit4 : below is the our junit4 suite class :

@RunWith(Suite.class)
@SuiteClasses({ 
    ClassA.class, 
    ClassB.class, 
    ClassC.class 
    } )
public class TestSuite {

}

The Code i tried after searching around is below :

@RunWith(JUnitPlatform.class)

@SelectClasses( { 
    OrderAnnotationAlphanumericExperiment.class, 
    orderAnnotationExperiment.class, 
    ParameterizedAnnotation.class 
    } )
public class TestSuite {
    

}

on searching for the solution, most of them were providing a solution of using the same test suite to run it using vintage api, but what am looking for is to create test suite in junit 5.

Few suggesting @ExtendsWith(SpringExtension.class), but there is also less documentation for it, couldn't able to find a solution to create a suite in junit 5

few blogs/question/sites i referred :

Create TestSuite in JUnit5 (Eclipse) Are test suites considered deprecated in JUnit5? https://howtodoinjava.com/junit5/junit5-test-suites-examples/

some one help me out to solve this problem.

like image 690
Dhuruvan Avatar asked Nov 07 '22 06:11

Dhuruvan


1 Answers

It's actually pretty easy. The following will find all JUnit tests in directory foo.bar.tests as well as it's subdirectories:

import org.junit.platform.runner.JUnitPlatform;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.SuiteDisplayName;
import org.junit.runner.RunWith;

@RunWith(JUnitPlatform.class)
@SuiteDisplayName("JUnit Platform Suite Demo")
@SelectPackages("foo.bar.test")
public class FullTestSuite 

}

See Sec 4.4.4 of the User's Guide.

like image 151
LJ in NJ Avatar answered Nov 09 '22 15:11

LJ in NJ