-
Notifications
You must be signed in to change notification settings - Fork 153
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
[#325] Spock 2 test support #326
Conversation
f48f91c
to
f9f1976
Compare
infinitest/infinitest-lib/src/main/java/org/infinitest/parser/JavaAssistClass.java Lines 62 to 71 in 9d5d53e
(a quick a dirty check for Spock tests fixes the execution, but it would be definitely "for Spock only", so we loose the ability to find any junit-platform engine's test - so maybe you have a better idea) |
f9f1976
to
42ae973
Compare
import java.util.List; | ||
|
||
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if Junit5Runner
shouldn't be renamed to JUnit5PlatformRunner
(or something similar) after these changes?
After rebased with master, I have the same mockito error, however, I'm not sure yet why it works in master, as I seem to change code in the other places... |
Hey @szpak thanks for the contribution and welcome back! |
42ae973
to
a5f6031
Compare
I think that Looking at the metadata with javaassist "for Spock only" sounds good to me. |
Keeping infinitest-lib not aware of testing frameworks have sense. Looking at its (our method) usage, it seems to be created to detect test among changed files and pass them to the runner. However, having some future changes around, you could check how it impacts performance (or other thing) to filter it out at the lib level (as it limits the vision to support of junit-platform engines at once :-( ). Regarding loading the framework related class, it seems the junit-jupiter "was leaked" as a infinitest-lib dependency: infinitest/infinitest-lib/pom.xml Lines 69 to 73 in 63d2fc6
and it's effectively loaded: infinitest/infinitest-lib/src/main/java/org/infinitest/parser/JavaAssistClass.java Lines 68 to 70 in 63d2fc6
Doing the Spock stuff, I can also improve that place to |
My comments about loading the classes were referring to the user's tests, I think it is fine if JUnit is loaded in the plugin. I'm not sure if you noticed it but I think that the important logic for JUnit tests detection is the one checking if a method is a test method, I think that the check on imports is a last resort. So I think it's fine to put something specific to Spock here. In case this becomes a problem it shouldn't be too difficult to make it more modular, for instance by checking what test libraries are on the classpath. |
|
||
void setup() { | ||
classPool = new ClassPool() | ||
classPool.appendSystemPath() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's enough in Idea, but with Maven, the tests fails with:
[ERROR] JavaAssistClassSpockSpec.should detect Spock 2 test (#clazz.simpleName):21 Condition failed with Exception:
classFor(clazz).isATest()
| |
| class org.infinitest.testdata.SimpleSpockSpec
java.lang.RuntimeException: javassist.NotFoundException: org.infinitest.testdata.SimpleSpockSpec
at org.infinitest.parser.JavaAssistClassSpockSpec.classFor(JavaAssistClassSpockSpec.groovy:30)
at org.infinitest.parser.JavaAssistClassSpockSpec.should detect Spock 2 test (#clazz.simpleName)(JavaAssistClassSpockSpec.groovy:21)
Caused by: javassist.NotFoundException: org.infinitest.testdata.SimpleSpockSpec
at javassist.ClassPool.get(ClassPool.java:450)
at org.infinitest.parser.JavaAssistClassSpockSpec.classFor(JavaAssistClassSpockSpec.groovy:28)
... 1 more
I extracted it to a separate module to do not have to put Spock 2 on the class path (and possibly any other testing framework which would start to be supported). Maybe you have an idea for the workaround?
@@ -409,4 +423,37 @@ public boolean locatedInClassFile() { | |||
public File getClassFile() { | |||
return classFile; | |||
} | |||
|
|||
private static class SpockIsTestClassChecker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class is quite big, so I created an inner class to (at least directly) do not enlarge it. Assuming, there is no way to avoid checking for testing frameworks in the lib module, probably it would be good to extract support for the particular frameworks to separate classes.
cb740ac
to
6c7a20e
Compare
And most likely also other 3rd-party JUnit Platform engines. Also bumped surefire version and added some toString() methods for better reporting in tests.
Checking in the lib module.
6c7a20e
to
b818af8
Compare
Hello @szpak, I've made some fixes to get the tests working, and also modified the "is it a test" logic to look for the Can you please give me write access to this branch on your repo, so I can push my changes there? |
Cool, I will take a look! I gave you a RW access to this branch when I originally made a PR (unless GitHub changed something in that matter recently). Have you tried and failed? Update. I don't see "Allow edits from maintainers." checkbox in this PR (as mentioned in docs), maybe it is a reason? |
Hmm, interesting. Spock - as far as I know - doesn't use it itself. However, if it works for you, I will take a look (once merged into this branch) to explain why :-). |
- Testable is more generic, this might pick up tests from other frameworks as well - Use infinitest-lib utility class to get the tests ClassPool
I'm not sure why I can't push my change (I don't seem to have the permissions) so I've submitted here: szpak-forks#1 |
Cool, I merged your change manually with fast-forward and after a quick look, Regarding write permissions, I created that form many years ago. Probably that feature was not available right there. I added you to the repository directly, if you want to add anything else. |
className = classReference.getName(); | ||
} | ||
|
||
private boolean isJUnit5TestClass(final String[] imports) { | ||
private boolean hasJUnit5TestImport(final String[] imports) { | ||
return stream(imports) | ||
.anyMatch(org.junit.jupiter.api.Test.class.getName()::equals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's outside a scope of this PR, but probably @Testable
could be used also for JUnit Jupiter tests.
I will play with it more tomorrow, but in general it looks good. |
Thank you! You seem to be the author of the |
Adding support for TestNG in 2013... I could forgot about that :-). Regarding |
added java unit tests for to check the logic
f9e62c1
to
65c259c
Compare
Thanks a lot for the contribution! |
And most likely also other 3rd-party JUnit Platform engines.
Also bumped surefire version and added some toString() methods for better reporting in tests.
TODO: All tests pass, but while testing in Idea 2022.1, the Spock test classes are detected as changed, but not executed. I have to bring back how it was possible to debug "live" Infinitest in Idea :). Maybe you will have an idea why?Fixed #325.