0

I have a OnApplicationEvent which executes some fancy scheduled code whenever the server spins up. What I want to do is disable/Override this Call for all at least some of my Unit Tests. I am working in Micronaut Application.

How can I do that?

pks18
  • 1
  • Does something like `@Requires(property="spec.name", value="SomeSpec")` help? – Jeff Scott Brown Jul 01 '21 at 12:43
  • Could you explain it in a bit more detail? I tried reading about @Requires but couldn't get it. – pks18 Jul 01 '21 at 13:50
  • If a bean in your app were marked with that annotation, the bean would only be loaded when the `SomeSpec` test is running. You could do things like provide a test specific bean that `@Replaces` an existing (production) bean. There are numerous options. – Jeff Scott Brown Jul 01 '21 at 14:31
  • I think it works. I added the annotation @Requires(notEnv = Environment.TEST). Now my Application class is not loading but the test are running just fine. Could you provide some link to resources where I can check sample codes to understand these annotations a bit more deeply. – pks18 Jul 01 '21 at 16:50
  • "Could you provide some link to resources where I can check sample codes to understand these annotations a bit more deeply." - Some relevant info is available at https://docs.micronaut.io/2.5.7/guide/#replaces and https://docs.micronaut.io/2.5.7/guide/#factories. – Jeff Scott Brown Jul 01 '21 at 17:41

1 Answers1

0

The answer from pks18 on the @Requires(notEnv = Environment.TEST) helped me.