Spring 3+ How to create a TestSuite when JUnit is not recognizing it

本秂侑毒 提交于 2019-12-03 14:28:17
NamshubWriter

You are right; JUnit4-style tests should not extend junit.framework.TestCase

You can include a JUnit4 test as part of a JUnit3 suite this way:

public static Test suite() {
   return new JUnit4TestAdapter(MyAppTest.class);
}

Usually you would add this method to the MyAppTest class. You could then add this test to your larger suite:

 public class AllTests {
   public static Test suite() {
     TestSuite suite = new TestSuite("AllTests");
     suite.addTest(MyAppTest.suite());
     ...
     return suite;
   }
}

You can create a JUnit4-style suite by creating a class annotated with Suite

@RunWith(Suite.class)
@SuiteClasses( { AccountTest.class, MyAppTest.class })
public class SpringTests {}

Note that AccountTest could be a JUnit4-style test or a JUnit3-style test.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!