JUnit parameterized tests: how do I run only 1 specific test from IntelliJ/Eclipse?

前端 未结 5 950
名媛妹妹
名媛妹妹 2021-02-03 20:06

I have a @Parameterized junit test that spawns 50 tests:

@RunWith(Parameterized.class)
public class NurseRosteringSolveAllTurtleTest ... {

    @Par         


        
相关标签:
5条回答
  • 2021-02-03 20:38

    Similarly to Miguel's answer, if you are using the JUnit 5's

    @ParameterizedTest
    @CsvFileSource(resources = arrayOf("/sender.csv"))
    

    you can go to your csv file and "comment out" some lines by prepending the # character to them.

    0 讨论(0)
  • 2021-02-03 20:40

    For a subset of tests ex( 27 & 28 ) Just add:

    `.subList( startInclusive, stopExclusive );`
    

    before returning your parameters collection.

    Non consecutive subsets:

    Collection<Object[]> c = Arrays.asList( data ).subList( startInclusive, stopExclusive );
    c.add( another subset );
    return c;
    
    0 讨论(0)
  • 2021-02-03 20:42

    Not sure if it will help, but you can try a trick which I used with Eclipse and JUnit parameterized tests.

    In JUnit launch configuration in "Test method" field you can write the full name of parameterized test, in your example it should be something like this 'solveDataFile[28: /path/to/your/file]'. Eclipse will complain that method does not exist but will still lunch it successfully.

    0 讨论(0)
  • 2021-02-03 20:54

    Eclipse is now (as of the Mars M4 release) able to run not just a single test from the Parameterized test class but any kind of subtree.

    This can be:

    • all methods for a single data set as returned by the @Parameterized-method
    • all datasets for a single @Test-method

    And as already mentioned, the test can also be specified by entering the tests name into the "method" text filed within the launch configuration. There will be a marker indicating that the method doesn't exist, but the test will run anyway.

    See this blog post for details.

    0 讨论(0)
  • 2021-02-03 21:02

    I just tested this in Eclipse with a simple parameterized test that always fails on test #4. One is able to right-click on the failed test and select Run. Only that test then executes.

    test output

    Result:

    just test 4

    Frustratingly, I can't see what Eclipse did to solve the problem. Nothing is apparently altered in the run configuration. In particular, if you select to run the configuration a second time, it executes all the tests.

    Some further testing shows that Eclipse will regenerate all 10 parameter values, but only uses the 4th value. (This was determined by embedding a print statement in the @Parameters method).

    0 讨论(0)
提交回复
热议问题