Intellij Idea 未找到用于参数化JUnit4测试的测试

hpcdzsge  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(72)

我试图从我的src/main类中的一个queue中参数化一个JUnit 4测试。这是我到目前为止所做的,有一个测试套件类(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时,结果是它找不到任何测试,当我调试它时,它显示:
org.junit.internal.requests.FilterRequest.getRunner上未找到与org.junit.runner.Request中的任何参数匹配的测试数据
我做错了什么?我应该在TestNG中更好地实现它吗?我真的是Junit的新手。

uwopmtnx

uwopmtnx1#

你可以试试这个:

mvn clean install -Dtest=MigratorTestSuite test

字符串

p8ekf7hl

p8ekf7hl2#

data方法应该返回一个对象数组的集合,即Collection<Object[]>。每个对象数组都是一个测试向量,包含例如输入String和预期结果。
测试类构造函数应该将测试向量的元素作为参数。在上面的例子中,它将接受一个String和一个outcome参数,您通常会将其存储在一个字段中,以便实际的测试用例可以使用它。对于每个测试向量,都会创建一个新的测试类示例。
在你的例子中,你似乎想使用一系列场景作为参数。
因此,你的data方法应该返回一个scenario-arrays 的集合(每个数组的长度为1),而你的构造函数应该使用一个 single scenario(而不是整个集合;所以不需要'peek' around)。

相关问题