简体   繁体   English

Junit-覆盖默认行为以仅运行测试一次,即使它们多次添加(在不同的套件中)

[英]Junit - Override default behaviour to run tests only once, even if they are added several times (in different Suites)

For our usecase, as an example - we need to run a JUnit test, even if it is added multiple times within a Test Suite, without being skipped. 以我们的用例为例-我们需要运行一个JUnit测试,即使它在测试套件中被多次添加,也不能被跳过。

Currently we notice that JUnit test runner skips a Test with the same name, if it finds the test somewhere else within a Test Suite. 当前,我们注意到,如果JUnit测试运行程序在Test Suite中的其他位置找到该测试,则会跳过具有相同名称的Test。 Here is an example screenshot to show test "Case_A" within "Procedure_A" being skipped within a Test Suite - 这是一个示例屏幕截图,显示了在“测试套件”中跳过“ Procedure_A”中的测试“ Case_A”-

在此处输入图片说明

Could this behaviour be overriden, if so could someone point us in the right direction? 如果有人可以指出我们正确的方向,可以否改掉这种行为?

I did some research arround this problem. 我围绕这个问题做了一些研究。

Simple setting - one Test "TestCase_A" and one Suite "TestProcedure_A" that runs the TestCase_A twice : 简单的设置-一个测试“ TestCase_A”和一个套件“ TestProcedure_A”,两次运行TestCase_A:

public class TestCase_A {

@Test
public void test() throws Exception {
    System.out.println("Case_A RUN");
    Assert.assertTrue(true);
  }
}

@RunWith(Suite.class)
@Suite.SuiteClasses({ TestCase_A.class, TestCase_A.class })
@SuppressWarnings("all")
public class TestProcedure_A {
}

I run the test Suite using Eclipse and maven. 我使用Eclipse和Maven运行测试套件。 Finding: The sysout statement actually shows, that the TestCase_A runs twice! 发现:sysout语句实际上显示,TestCase_A运行两次!

Therefore, the Eclispe View is misleading. 因此,Eclispe视图具有误导性。 Test are run multiple times - the tree also reflects this. 测试被多次运行-树也反映了这一点。 However, the status of the actual single calls is not displayed properly in the Eclispe Junit View. 但是,实际的单个呼叫的状态在Eclispe Junit视图中无法正确显示。

I presume the view is based on the junit.runner.TestRunListener . 我认为该视图基于junit.runner.TestRunListener It probably worth looking into that. 可能值得研究。

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

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