【问题标题】:Exception on running parameterized test with junit5使用junit5运行参数化测试的异常
【发布时间】:2019-01-24 08:28:19
【问题描述】:

我在尝试将参数化测试与 Spring Boot 应用程序集成时遇到 Junit Vintage 初始化错误。有解决这个问题的指点吗?

  @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>

【问题讨论】:

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


    【解决方案1】:

    我通过用注释类解决了这个问题

    @ExtendWith(SpringExtension.class)
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 2019-01-23
      • 2017-05-23
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      • 2020-09-21
      • 2019-04-08
      • 1970-01-01
      相关资源
      最近更新 更多