How to reuse existing JUnit tests in another test class?

后端 未结 4 1139
广开言路
广开言路 2020-12-16 09:29

how can I reuse JUnit tests in another testclass?

For example:

public TestClass1 {
    @Test
    public void testSomething(){...}
}

public TestClass         


        
4条回答
  •  眼角桃花
    2020-12-16 10:18

    Logically, there is no reason to call one test method from another. Any tool that runs one test would just as easily all tests in the package. But if you need to, you'd call it like any other method in any other class.

    What you most likely want to do, is perform some common setup for both test methods. You could put that code in a utility method in a common class, and invoke the common code in both tests.

提交回复
热议问题