在使用TestSuite时,可以避免在eclipse中运行junit测试两次吗? [英] Can I avoid running junit tests twice in eclipse when using a TestSuite?

查看:136
本文介绍了在使用TestSuite时,可以避免在eclipse中运行junit测试两次吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对每个套件进行一些初始化(启动Web服务器)。它工作正常,除了当我在eclipse中的项目中运行所有测试我的测试运行两次。我的测试套件看起来有点像这样:

I need to do some per-suite initialisation (starting a web-server). It is working fine except that when I run all tests in my project in eclipse my tests run twice. My test suite looks a bit like this:

@RunWith(Suite.class)
@Suite.SuiteClasses({
   SubtestOne.class,
   SubtestTwo.class
})
public class TestSuite
{
   [...]
}

public class SubtestOne
{
   @Test public void testOne() { [...] }
}

public class SubtestTwo
{
   @Test public void testTwo() { [...] }
}

当我在eclipse中运行项目中的所有测试时,这将导致junit插件运行测试两次,如下所示:

When I run all test in project in eclipse this causes the junit plugin to run the tests twice like this:


  • SubtestOne

  • SubtestTwo

  • TestSuite

    • SubtestOne

    • SubtestTwo

    • SubtestOne
    • SubtestTwo
    • TestSuite
      • SubtestOne
      • SubtestTwo

      有可能使运行项目中的所有测试不运行次测两次?我想我的子测试只能作为套件的一部分运行。

      Is it possible to make "run all test in project" not run the sub-tests twice? I want my sub tests to be only ever run as part of the suite.

      推荐答案

      不,测试类将始终被启动直接然后通过套件中的链接。这是如预期的。

      No, the test class will always be started directly and then through the "link" in the suite. This is as expected.

      可以在运行配置中设置一个解决方法,只能从包含您的套件的包运行测试。打开运行配置,然后选择在选定的项目,包或源文件夹中运行所有测试,然后单击搜索... 并选择包裹。

      One workaround might to set in the run configuration to only run tests from the package which contains your suites. Open the run configuration and select Run all tests in the selected project, package or source folder then click Search... and select the package.

      这篇关于在使用TestSuite时,可以避免在eclipse中运行junit测试两次吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆