Configuration error: You must configure at least one set of arguments for this @ParameterizedTest

Configuration error: You must configure at least one set of arguments for this @ParameterizedTest

我正在尝试 运行 测试接口并阅读我应该使用 @ParameterizedTest。错误如下所示。

这是我的代码:

package de.rhenus.fl.dpx.commons.mapstruct.date;

import de.rhenus.fl.dpx.commons.business.micronaut.date.EmbeddedOffsetDateTimeOracle;
import org.junit.jupiter.params.ParameterizedTest;

import java.time.OffsetDateTime;

import static org.hamcrest.MatcherAssert.assertThat;

class EmbeddedOffsetDateTimeOracleMapperTest {
    final EmbeddedOffsetDateTimeOracleMapper mapper;
    final OffsetDateTime NOW = OffsetDateTime.now();


    public EmbeddedOffsetDateTimeOracleMapperTest(EmbeddedOffsetDateTimeOracleMapper mapper) {
        this.mapper = mapper;
    }

    @ParameterizedTest
    void embeddedOffsetDateTimeOracleToOffsetDateTime() {
        EmbeddedOffsetDateTimeOracle embeddedOffsetDateTimeOracle = new EmbeddedOffsetDateTimeOracle();
        embeddedOffsetDateTimeOracle.setOffset(0);
        embeddedOffsetDateTimeOracle.setValue(NOW.toLocalDateTime());

        OffsetDateTime result = mapper.map(embeddedOffsetDateTimeOracle);
        assertThat("Same OffsetDateTime", result.equals(NOW));

    }

    @ParameterizedTest
    void offsetDateTimeToEmbeddedOffsetDateTimeOracle() {
        EmbeddedOffsetDateTimeOracle embeddedOffsetDateTimeOracle = new EmbeddedOffsetDateTimeOracle();
        embeddedOffsetDateTimeOracle.setOffset(0);
        embeddedOffsetDateTimeOracle.setValue(NOW.toLocalDateTime());

        OffsetDateTime result = mapper.map(embeddedOffsetDateTimeOracle);
        assertThat("Same OffsetDateTime", result.equals(NOW));

    }
}

这是我的错误:

Configuration error: You must configure at least one set of arguments for this @ParameterizedTest org.junit.platform.commons.PreconditionViolationException: Configuration error: You must configure at least one set of arguments for this @ParameterizedTest at org.junit.platform.commons.util.Preconditions.condition(Preconditions.java:281)

我需要在哪里将参数传递给 运行 我的测试?

对于 Junit5,对于每个参数化测试,您都需要传递一个值集。您可以参考相同的文档:https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests .

在您的情况下,应该如下所示:


    @ParameterizedTest
    @ValueSource(ints = { -3, 0, 1, 2, 3 })
    void offsetDateTimeToEmbeddedOffsetDateTimeOracle(int offset) {
        EmbeddedOffsetDateTimeOracle embeddedOffsetDateTimeOracle = new EmbeddedOffsetDateTimeOracle();
        embeddedOffsetDateTimeOracle.setOffset(offset);
        embeddedOffsetDateTimeOracle.setValue(NOW.toLocalDateTime());

        OffsetDateTime result = mapper.map(embeddedOffsetDateTimeOracle);
        assertThat("Same OffsetDateTime", result.equals(NOW + offset));

    }