I am trying to run tests of a interface and read that i should use @ParameterizedTest. The error is shown below.
Here's my code:
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));
}
}
Here's my error:
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)
Where do I need to pass parameters to run my test?
CodePudding user response:
For Junit5, for each parameterized test, you would need to pass a value set. You can refer to the documentation for the same: https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests .
In your case, it should be something as follow:
@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));
}