使用junit5运行参数化测试时发生异常

时间:2019-01-24 08:28:20

标签: java-8 junit5 parameterized-unit-test

尝试将参数化测试与Spring Boot应用程序集成时,出现Junit Vintage初始化错误。关于解决此问题的任何指示?

enter image description here

  @ParameterizedTest(name="Run {index}: loanAmount={0}, downPayment={1}, availableFunds={2}, expectApproved={3}, expectedMessage={4}")
    @MethodSource("testRequestLoan_Parameters")
    public void testRequestLoan(float loanAmount, float downPayment, float availableFunds,
                                boolean expectApproved, String expectedMessage) throws Throwable
    {
    }

    static Stream<Arguments> testRequestLoan_Parameters() throws Throwable {
        return Stream.of(
                Arguments.of(1000.0f, 200.0f, 250.0f,  true, null),
                Arguments.of(1000.0f,  50.0f, 250.0f, false, "error.insufficient.down.payment"),
                Arguments.of(1000.0f, 200.0f, 150.0f, false, "error.insufficient.funds.for.down.payment")
        );
    }

依赖项

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>5.3.2</version>
            <scope>test</scope>
        </dependency>

1 个答案:

答案 0 :(得分:1)

我通过为课程添加注释来解决了这个问题

@ExtendWith(SpringExtension.class)