spring-cloud-contract
spring-cloud-contract copied to clipboard
Add the possibility to specify custom test annotations via the spring-cloud-contract-maven-plugin
Is your feature request related to a problem? Please describe.
The spring-cloud-contract-maven-plugin
has the option of specifying imports
and static imports
for the generated tests. Sometimes you might need to add some custom annotations to the tests, for instance when using OpenEJB
to start a TomEE
server with JAX-RS
services you have to add the @EnableServices(value = "jaxrs")
and @RunWith(ApplicationComposer.class)
annotations to each test because they are not inherited from the base test class.
Describe the solution you'd like
The plugin should accept a configuration XML element similar to the existing imports
and static imports
.
Describe alternatives you've considered
The alternative is to create a separate library which defines a custom JavaTestGenerator
and reference it as a dependency but it would be much easier just to define annotation(s) at the configuration
level.
Additional context Add any other context or screenshots about the feature request here.
Hi @virgiliu-ratoi-ec-ext , won't you be able in do this setup in the test base class?
Hi @virgiliu-ratoi-ec-ext , won't you be able in do this setup in the test base class?
Unfortunately, the required annotations from the test base class are not inherited so they need to be specified in the child class.
That's a good idea. So the plugin setup would require a list of FQN imports for the annotation e.g. <imports>a.b.c.EnableServices</imports>
and sth like classAnnotations, methodAnnotations ? e.g. <classAnnotations>@EnableServices(value = "jaxrs")</classAnnotations>
?
As a workaround you can check out this issue and do sth similar as described here in this issue https://github.com/spring-cloud/spring-cloud-contract/issues/1074 with the replacer plugin
That's a good idea. So the plugin setup would require a list of FQN imports for the annotation e.g.
<imports>a.b.c.EnableServices</imports>
and sth like classAnnotations, methodAnnotations ? e.g.<classAnnotations>@EnableServices(value = "jaxrs")</classAnnotations>
?As a workaround you can check out this issue and do sth similar as described here in this issue #1074 with the replacer plugin
Indeed, something like that could make things easier. Of course, there is the option you mentioned with the maven-replacer-plugin
which I was not aware of.