我正在尝试从先前在我的 src/main 类之一中设置的 queue
参数化 JUnit4 测试。这就是我到目前为止所做的,有一个测试套件的类 (MigratorTestSuite
)
@RunWith(Suite.class)
@Suite.SuiteClasses({ParameterizedTest.class})
public class MigratorTestSuite {
@BeforeClass
public static void setUp() throws SAXException, ParserConfigurationException, GitAPIException, IOException {
Migrator.getReady();
}
@AfterClass
public static void tearDown() throws SQLException {
DatabaseManager.closeConnections();
RepositoryManager.closeRepository();
}
}
还有一个类ParameterizedTest
,我正在其中弄清楚如何运行 parameterized JUnit test如下所示:
@RunWith(Parameterized.class)
public class ParameterizedTest {
@Parameterized.Parameters(name="whatever")
public static Queue<Deque<String>> data(){
return TestCasesConstructor.testCasesQueue;
}
private Deque<String> scenario;
public ParameterizedTest(Queue<Deque<String>> q){
scenario = q.peek();
}
@Before
public void initialize() throws ParserConfigurationException, IOException, SQLException, ClassNotFoundException {
System.out.println("--- Preparing database for running scripts");
DatabaseManager.dropDatabase();
DatabaseManager.createDatabase();
}
@Test
public void testPlainMigration() throws Exception {
Assert.assertTrue(Migrator.runScenario(this.scenario));
}
@After
public void after() throws SQLException {
DatabaseManager.closeConnections();
TestCasesConstructor.testCasesQueue.remove();
}
}
当我执行 mvn clean install test -Dtest=MigratorTestSuite
时,结果是它找不到任何测试,当我调试它时,它显示:
No tests found matching data with any parameter from
org.junit.runner.Request
atorg.junit.internal.requests.FilterRequest.getRunner
我做错了什么?我应该更好地在 TestNG 中实现它吗?我对 Junit 还很陌生。
最佳答案
你可以试试这个:
mvn clean install -Dtest=MigratorTestSuite test
关于java - 未找到参数化 JUnit4 测试的测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35211102/