【问题标题】:How to two runner property include in one test case class?如何将两个 runner 属性包含在一个测试用例类中?
【发布时间】:2016-01-09 13:59:10
【问题描述】:
 @RunWith(DataProviderRunner.class)
   @RunWith(SpringJUnit4ClassRunner.class)
    public class DatabaseModelTest {   
   // some tests
     }

    @RunWith(Parameterized.class)
       @RunWith(SpringJUnit4ClassRunner.class)
       public class DatabaseModelTest {   
      // some tests
       }
  • 我们不能在一个测试用例类中使用两个 runner 属性...!!这样
  • 我想用多个数据运行测试用例我如何在 Rest web 服务中传递多个参数来执行测试用例??

  • DataProviderRunner 的扩展类或参数化的任何解决方案?

谢谢 (保持连接52)

【问题讨论】:

  • 为什么不使用自己的跑步者来合并其他两个人的行为?
  • 请举个例子,我尝试过扩展类并在超类中设置跑步者,但它无法获得该跑步者@juherr 的属性!给我一个例子你想说什么?谢谢。
  • 为什么需要两个跑步者?这两个运行器是参数化测试的不同方法。通常你应该只需要其中一个。
  • @StefanBirkner 编辑 ..感谢 Sprint junit 测试类执行和数据提供者第二个

标签: junit parameterized testng-dataprovider


【解决方案1】:

您可以使用 Spring 的 JUnit 规则而不是 SpringJUnit4ClassRunner。这至少适用于 Parameterized 跑步者。我不知道它是否也适用于DataProviderRunner。 您至少需要 4.2.0 版的 Spring 框架和 spring-test。

@RunWith(Parameterized.class)
public class DatabaseModelTest {   
  @ClassRule
  public static final SpringClassRule SCR = new SpringClassRule();

  @Rule
  public final SpringMethodRule springMethodRule = new SpringMethodRule();

  ...
}

【讨论】:

  • 你能解释一下如何定义@classrule并得到类似at ClassRule 'SCR' must implement MethodRule or TestRule
  • 您使用的是哪个版本的 JUnit?您应该使用 JUnit 4.12。
  • 得到了解决方案,感谢问题是 Spring 版本的答案更新了.. 在你的答案中
【解决方案2】:

我测试了@Stefan 的解决方案,也适用于@RunWith(DataProviderRunner.class)

我在DataProvider for Spring Integration Testing找到了第二个解决方案,他们写了一个类DataProviderRunnerWithSpring 并将测试类设置为:

@RunWith(DataProviderRunnerWithSpring.class)
public class TestClass{ 
... 
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多