繁体   English   中英

在intellij中运行参数化junit测试的单个场景

[英]running a single scenario of a parametrized junit test in intellij

我有一个参数化的junit测试,有几个场景,需要能够只运行其中一个场景。

我想在IntelliJ中做到这一点。 有谁知道怎么做?

这是一个代码示例:

这是场景,参数和测试方法的集合:

@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);
   }
}

我希望能够只运行一个场景。 我想做的比从IntelliJ GUI或Junit Runner做起。

运行所有方案一次后,可以在“运行”窗口中右键单击其中一个,然后运行或调试它。 这个解决方案并不理想,因为整个套件需要先运行才能运行一个。

您可以通过在运行/调试配置中的方法名称末尾添加参数来传递参数。 IntelliJ将显示警告但它将正确运行JUnit测试。 适用于原始类型,字符串和枚举,不确定它如何适用于复杂对象。

例:

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

Method in the configuration: testDoSomething[MyEnum: VALUE1]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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