gpt4 book ai didi

java - 使用 TestSuite 时,我可以避免在 Eclipse 中运行两次 junit 测试吗?

转载 作者:太空狗 更新时间:2023-10-29 22:47:32 26 4
gpt4 key购买 nike

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

@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 插件像这样运行测试两次:

  • 子测试
  • SubtestTwo
  • 测试套件
    • 子测试
    • 小测验

是否可以让“在项目中运行所有测试”不运行子测试两次?我希望我的子测试只作为套件的一部分运行。

最佳答案

不会,测试类总是会直接启动,然后通过套件中的“链接”启动。这符合预期。

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

关于java - 使用 TestSuite 时,我可以避免在 Eclipse 中运行两次 junit 测试吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931684/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com