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

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

问题描述

我需要对每个套件进行一些初始化(启动网络服务器).它工作正常,除了当我在 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:

  • 子测试一
  • 子测试二
  • 测试套件
    • 子测试一
    • 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.

    一种解决方法可能是在运行配置中设置只运行包含您的套件的包中的测试.打开运行配置并选择 Run all tests in the selected project, package or source folder 然后点击 Search... 并选择包.

    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天全站免登陆