-
Notifications
You must be signed in to change notification settings - Fork 79
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
RemoveTestPrefix
should not (only) rename methods called from other methods
#258
Comments
Note: this issue is a bit more visible now that |
Just to offer up a test case for the first issue listed above as we ran into this in our codebase: @Test
void testRemoveTestPrefixWithClashingMethod() {
rewriteRun(
spec -> spec.recipe(new RemoveTestPrefix()),
java(
"""
package com.spotify.helloworld;
import org.junit.jupiter.api.Test;
import static java.util.List.of;
public class FooTest {
@Test
void testOf() {
of();
}
}"""));
} I can put this test in a PR if that is preferable. Not sure I'd know how to fix it though. |
Thanks @protocol7 ; this one was easy it seems; |
* Skip RemoveTestPrefix when calling a similarly named method #258 * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
RemoveTestPrefix
should not rename methods called from other methods
RemoveTestPrefix
should not rename methods called from other methodsRemoveTestPrefix
should not (only) rename methods called from other methods
We could maybe fix the remaining issue (within a single class) by switching to |
Not sure if the same issue as discussed here, but here's an issue we're seeing when a test method is called by a different test method: @Test
void removeTestPrefixWhenCalled() {
rewriteRun(
spec -> spec.recipe(new RemoveTestPrefix()),
// language=java
java(
"""
package com.helloworld;
import org.junit.jupiter.api.Test;
public class FooTest {
@Test
void bar() {
testFoo();
}
@Test
void testFoo() {}
}
""",
"""
package com.helloworld;
import org.junit.jupiter.api.Test;
public class FooTest {
@Test
void bar() {
foo();
}
@Test
void foo() {}
}
"""));
} Unexpected result in "com/helloworld/FooTest.java": diff --git a/com/helloworld/FooTest.java b/com/helloworld/FooTest.java
index f0cd70f..222415f 100644
--- a/com/helloworld/FooTest.java
+++ b/com/helloworld/FooTest.java
@@ -5,7 +5,7 @@
public class FooTest {
@Test
void bar() {
- foo();
+ testFoo();
}
@Test In this case, either |
Thanks for the runnable example @protocol7 ; That's indeed what I had intended with the second not-yet-crossed-off todo item here. I think we'll both agree it's not optimal or expected for test methods to also be invoked directly, but perhaps best to guard against that. This would be relatively straightforward for usages from within the same class; a little more effort for usages from other classes. For the simplest case I think this still stands:
Did you already explore that using the runnable test you have? |
I have not tried to fix this one, and probably won't be able to in a near term future. And, agree on this been a poor practice, but in large code bases, everything will appear at least once :) |
Quickly noted down here, can be tackled individually.
The text was updated successfully, but these errors were encountered: