简体   繁体   中英

running a single scenario of a parametrized junit test in intellij

I have a Parameterized junit test with several scenarios & need to be able to run just one of the scenarios.

I would like to do it in IntelliJ. Does anyone know how to?

Here's a code example:

Here's the collection of scenarios, the parameter and the test method:

@RunWith(Parameterized.class)
public class MyTest {

   @Parameterized.Parameters(name = "{index}: {0}")                
   public static List<String[]> e2e_scenarios() {                  
       return  Arrays.asList(new String[][]{                       
               {"scenario 1"},                                  
               {"scneario 2"}, 
       });
   }       

   @Parameterized.Parameter       
   public String scenarioName;    

   @Test
   public void testrScenario() {
       System.out.println("running scenario " + scenarioName);
   }
}

I want to be able to run just a single scenario. Preferably, I would like to do than from the IntelliJ GUI or Junit Runner.

After running all the scenarios once, it is possible to right click one of them in the "run" window and run or debug just it. This solution is not ideal, because the entire suite need to run prior to being able to run just one.

You can pass your parameter by adding it at the end of the method name in the run/debug configuration. IntelliJ will show a warning but it will run JUnit test properly. Works for primitive types, Strings, and Enums, not sure how it will work for complex objects.

Example:

@Parameterized.Parameters(name = "MyEnum: {0}")
public static setParameters() {
   ...
}

Method in the configuration: testDoSomething[MyEnum: VALUE1]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM