-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
junit-jupiter-params dependency is not added for @ParameterizedTest #574
Comments
Hi! We have a recipe step that should add this dependency: rewrite-testing-frameworks/src/main/resources/META-INF/rewrite/junit5.yml Lines 119 to 125 in 05c2094
That runs after the recipe that should convert you test class.
Are you seeing the corresponding change on your test class already? That's not immediately clear from the above. |
There were a few details missing above, but with some effort I was able to replicate your problem with a unit test: @Test
@Issue("https://github.com/openrewrite/rewrite-testing-frameworks/issues/574")
void junitParamsDependencyAdded() {
rewriteRun(
mavenProject("project",
srcTestJava(
//language=java
java(
"""
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
@RunWith(value = Parameterized.class)
public class DataCopyTest {
public enum QueryStyle {
FOO, BAR
}
@Parameterized.Parameter
public QueryStyle queryStyle;
@Parameterized.Parameters(name = "QueryStyle.{0}")
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{QueryStyle.FOO}, {QueryStyle.BAR}});
}
@Test
public void someTest() {
assertTrue((queryStyle.equals(QueryStyle.FOO) || queryStyle.equals(QueryStyle.BAR)));
}
}
""",
"""
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.Collection;
public class DataCopyTest {
public enum QueryStyle {
FOO, BAR
}
public QueryStyle queryStyle;
public static Collection<Object[]> data() {
return Arrays.asList(new Object[][] {{QueryStyle.FOO}, {QueryStyle.BAR}});
}
@MethodSource("data")
@ParameterizedTest(name = "QueryStyle.{0}")
public void someTest(QueryStyle queryStyle) {
initDataCopyTest(queryStyle);
assertTrue((queryStyle.equals(QueryStyle.FOO) || queryStyle.equals(QueryStyle.BAR)));
}
public void initDataCopyTest(QueryStyle queryStyle) {
this.queryStyle = queryStyle;
}
}
"""
)
),
//language=xml
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>project</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.7.18</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.10.3</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>project</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.3.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<version>2.7.18</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
"""
)
)
);
} |
Hey @timtebeek thanks for replying already! Sorry for not being clearer above. On a tangential note: I also observed that the |
No worries; it's just that we need the full context to write a unit test to replicate the issue, to make it runnable and debug it.
Yes please! A quick draft PR would be even more appreciated, as we have some examples already. rewrite-testing-frameworks/src/main/resources/META-INF/rewrite/junit5.yml Lines 112 to 114 in 05c2094
|
Great, I'll create the ticket for now. I will see if I can create the PR in the evening, when I am back from work. |
On the topic of this issue I've found that if I remove the
Not quite sure of the cause just yet. There does not already appear to be any such transitive dependency on the input pom.xml.
|
By the way, the repository that I am running this on is: https://gerrit.onap.org/r/admin/repos/aai/aai-common,general |
I think we are suffering from the same thing (however, I was experiencing it in hamcrest->assertj migration). I created a reproducer here. If this is not the same thing (a problem with |
What version of OpenRewrite are you using?
2.16.0
How are you running OpenRewrite?
I am applying the Maven Command Line command on a single module project.
Can you share your configuration so that we can rule out any configuration issues?
I am not explicitly changing any configuration.
What is the smallest, simplest way to reproduce the problem?
pom.xml that doesn't have a dependency that (transitively) adds
junit-jupiter-params
(i.espring-boot-starter-test
):What did you expect to see?
or more specific to spring-boot:
What did you see instead?
No change to those dependencies.
The text was updated successfully, but these errors were encountered: