简体   繁体   English

JUnit套件运行器执行一种方法

[英]JUnit suite runner to execute one method

I have a test suite that runs all test classes 我有一个可以运行所有测试类的测试套件

    @RunWith(Suite.class)
    @Suite.SuiteClasses({TestClass1.class, TestClass1.class})
    }

    public class AllTests extends TestCase {

      public AllTests(String name) {
        super(name);
      }

      public static TestSuite suite() {
        TestSuite suite = new TestSuite("com.myapp.test.AllTests"); 
        return suite;
      }
}

is it possible to implement a custom runner that will run only one method, say "onlyMethodToRun", from every class in the suite? 是否有可能实现一个自定义运行程序,该自定义运行程序将从套件中的每个类仅运行一个方法,例如“ onlyMethodToRun”?

Yes. 是。 Suite.java implements a test runner that examines the classes listed in @Suite.SuiteClasses and uses RunnerBuilder s to find every test method. Suite.java实现了一个测试运行程序,该运行程序检查@Suite.SuiteClasses列出的类,并使用RunnerBuilder查找所有测试方法。 You should be able to reuse a lot of JUnit's code to implement a Runner that instead only checks for a single method on every class and perhaps uses a subclass of BlockJUnit4ClassRunner that overrides computeTestMethods to only attempt a single method. 您应该能够重用许多JUnit的代码来实现Runner ,该Runner只会在每个类上检查单个方法,并且可能会使用BlockJUnit4ClassRunner的子类,该子类将重写computeTestMethods以便仅尝试单个方法。

暂无
暂无

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

相关问题 带套件的Junit Test Runner - Junit Test Runner with Suite 在junit中执行测试套件的订单 - Execute order for test suite in junit Maven jUnit5 org.junit.platform.runner, org.junit.platform.suite.Z8A38A5DA52EDC126427 不存在 - Maven jUnit5 org.junit.platform.runner, org.junit.platform.suite.api does not exist 如何在测试套件中定义 JUnit 方法规则? - How to define a JUnit method rule in a test suite? JUnitException:ID 为“junit-platform-suite”的 TestEngine 无法执行测试 - JUnitException: TestEngine with ID 'junit-platform-suite' failed to execute tests 在junit4中执行测试方法 - Execute test method in junit4 Eclipse Photon:测试套件导致“使用测试运行器'JUnit 5找到Np测试”。”错误消息 - Eclipse Photon: Test Suite results in “Np test found with test runner 'JUnit 5”." error message java.lang.VerifyError: class com.intellij.junit4.JUnit4TestRunnerUtil$5 覆盖最终方法getRunner.()Lorg/junit/runner/Runner; - java.lang.VerifyError: class com.intellij.junit4.JUnit4TestRunnerUtil$5 overrides final method getRunner.()Lorg/junit/runner/Runner; IntelliJ Idea - JUnit5 - 出现错误 -> ['@Suite' 不适用于方法] - IntelliJ Idea - JUnit5 - Getting an error -> [ '@Suite' not applicable to method ] 如何编写在@Category中的TestCase之前运行@BeforeCategory方法的JUnit运行器? - How to write a JUnit runner that runs a @BeforeCategory method before a TestCase in a @Category?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM