Unroll - get original method name in JUnit listener
I am working on creating test impact analysis tool for Spock test cases, for which I need access to method name to maintain mapping from test methods to source methods or classes.
This is helpful to us for reducing the build time while running integration test cases.
We are using JUnit5 Listener to get the name of the test name and using Instrumentation to maintain the list of classes and methods touched/impacted by a particular test.
Once that mapping is maintained, once a developer makes changes to code, then we will make a reverse lookup from source method/source class to list of impacted tests that need to be run and only those.
But in case of @Unroll annotation it doesn't work for us, because the name is replaced with the values from provider.
@Unroll("Updated method")
def "This is original method name"() {
...
}
We are using Gradle for executing the build process. So to filter and run only a particular tests we need to pass original method names in gradle test task.
Question: Is there a way to get access to original method name from Junit 5 Listener?
If you are using 1.3, I don't think so. If you using 2.0 milestone build, many things changed and you could get it from the parent. But maybe it would be easier and more portable if you do not use a JUnit listener, but a Spock extension. You can have a feature interceptor that knows which feature is currently executed and you can get the name there.
@Vampire Aren't extensions available in 1.3?
We just hacked using 2.0 milestone and JUnit 5 listener and were able to get the information.
In our current scenario we have mix of JUnit and Spock test cases, in that scenario do you still recommend using Spock Extension mechanism?
We are listening for Junit methods using TestExecutionListener
Extensions are availble in 1.3 and 2.0 the same, that's why I said it is more portable to use them. But if you mix JUnit and Spock tests and get hold of the information you need, you are maybe better off using the JUnit listener.
@npathai which JUnit Platform listener class are you referring to? I would suggest to use the UniqueId if you have access to it. However, I don't know if gradle supports selecting by UniqueId yet.