-
Notifications
You must be signed in to change notification settings - Fork 471
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
Filtering by tags in JUnit 5 prevents Spock specs from being executed #1288
Comments
Tags are a JUnit Platform feature that Spock 2.0 doesn't support at the moment. @marcphilipp it might worthwhile to allow engines to opt-in to such features and ignore them otherwise. |
Yes, that's my point. Right now if you want to use tags you can't use any other engines together with Jupiter |
Tags are not a Jupiter but a Platform feature. Hence, if you include a certain tag, all engines will be filtered accordingly. The Vintage engine converts JUnit 4's |
@marcphilipp if tags are a platform feature why is the annotation |
That's the way to set a tag in Jupiter. Other engines can support different ways like for example category annotation or configuration file or naming convention or cyclomatic complexity of a method or data about previous runs and so on. The engine translates whatever means it sees fit to a platform tag on which you then can filter. |
So, if you are still on Spock 1.x you can use JUnit 4's |
Yeah, that would be helpful (too bad they can't work as meta-annotations). My point is: JUnit manual does a very bad job of explaining this whole thing, it only mentions Any chance of Spock 2 getting tag support now, that it became apparent that it's less feature-complete than 1.x? :D |
We are thinking about how to add it, but Spock always had its own way of including/excluding Specs and Features, and I'd argue it is more powerful. |
Powerful or not it doesn't work well with JUnit 5, as explained above it makes it necessary to have a separate execution. Also I've always found it awkward to have to edit a file to specify the options. There's no easy way to specify it directly from a gradle build (you could try https://stackoverflow.com/a/66371811/1237617). |
@jakub-bochenski Could you please open an issue in the junit5 repo for this? |
As the file is a groovy script, you can react to system properties / environment variables or other things to control what gets included/excluded. |
Just dropping in to say I discovered this very same issue today. Agree with @jakub-bochenski that having Spock 2.0 support the Tag annotation would be extremely helpful. |
Can we maybe add a global tag like
and
See https://junit.org/junit5/docs/5.0.0-M3/api/org/junit/platform/engine/TestDescriptor.html#getTags-- |
The main reason that Spock doesn't support this yet, is that there already exists an ITaggable and Tag in Spock, which have different semantics. This makes adding a new different kind of tag awkward in the API, simply renaming the existing one would be a breaking change. An alternative would be to simply overload the meaning of |
Any update on this issue? Our internal test runner was based on |
Nearly the same situation for me. EDIT: At least, I find someone that make something similar and put an example : https://github.com/Martin-BG/spock-jupiter-integration However, this requires to rename integration tests with the suffix "IT" |
That is the standard way for surefire ( |
I agree with @leonard84. I also use Maven whenever working with Spock, and I use convention over configuration, sticking to the Surefire and Failsafe default names, i.e. unit tests end have names like
Maybe you missed what @leonard84 said at the beginning of this thread:
I.e., the concept of tags are a platform feature, but the Having said that, I understand that it might be useful for the Spock engine (which is a sibling, not a child of the Jupiter engine on top of the JUnit 5 platform) to also offer a means to map some user-configurable information to tags. At the moment, it simply does not (yet). @leonard84: Actually, the main thing that is missing at the moment in include {
annotation org.junit.jupiter.api.Tag, { value.contains("fast") && !value.contains("slow") }
}
exclude {
annotation org.junit.jupiter.api.Tag, { value.equals("UI") }
} I.e., an optional closure parameter with filter criteria. For user convenience, the annotation instance could be bound already, I imagine something like Spock evaluating |
This wont solve the problem mentioned in this issue, as the platform is doing the filtering in this case not Spock. |
I was not talking about delegating to JUnit platform, not knowing the implications of the way spock generates test names for unrolled methods, but about extending the include exclude extension in such a way that we have an analog to it and can parametrise it from outside, say from a build tool like Maven. BTW, does the Spock engine "see" the platform config coming from e.g. the Maven JUnit 5 provider? Could it read the tags (categories) configuration in principle? Does the platform pass it through to the Spock engine? If so, where in the Spock source would I have to look? Maybe one of these days I want to play with some ideas, just for fun. |
Me neither, but this issues is about the case when you use test {
useJUnitPlatform {
includeTags("SomeTag")
}
} In this case the plattform is doing the filtering and removes all Spock tests, because Spock returns an empty list of tags here https://github.com/junit-team/junit5/blob/718b6937415dd825383641f9ddb00ce12f4640fb/junit-platform-engine/src/main/java/org/junit/platform/engine/TestDescriptor.java#L78 |
Fixed by #1467 |
Hiya, how do I now make test suites that works with Maven? I've been using Spock 2.x Groovy 3.x, and Categories don't work with Maven. I've been wanting to run a Test Suite through Maven, and all of the documentation only show support for Gradle. |
That is on the JUnit Platform level and you can read about it here: https://junit.org/junit5/docs/current/user-guide/#running-tests-build-maven-filter-tags |
Is there a timeline on when that will be released? |
If you don't have to interoperate with other test engines, I suggest to use Spock's built-in include/exclude functionality that has been available for a long time. |
Description
This comes from Junit's
EngineDiscoveryOrchestrator
I think this clearly shows there is a bug. Tags should not affect other engines than Jupiter.
How to reproduce
Add some Spock 1.x Specs and have a gradle test task configured as follows:
Observe specs are not being executed.
If you comment out the line with "includeTags" the specs are executed.
I've checked in the debugger that a
RunnerTestDescriptor
with aSputnik
runner is being discovered (the Specs are not being skipped/ignored by Spock).The same happens with Spock 2.x
Also reported as junit-team/junit5#2563
Additional Environment information
The text was updated successfully, but these errors were encountered: