1

I'm trying to use Micronaut-jms to integrate ActiveMQ Artemis into my application. Everything worked perfectly until I started writing unit tests.

The issue I'm facing is that since my test's are annotated with @MicronautTest when I run a test the whole application boots up. All would be fine except the application will look for ActiveMQ Artemis, and as it is embedded and has not started yet, the application will throw an error and the test will fail.

Here is a demo application.

How can I ensure that the embedded ActiveMQ Artemis is available for the application?

The test itself:

@MicronautTest
class DemoControllerSpec extends Specification {

    @Shared
    ActiveMQServer server

    void setup() {
        Configuration config = new ConfigurationImpl()
        config.addAcceptorConfiguration("in-vm", "vm://0")
        //config.addAcceptorConfiguration("tcp", "tcp://127.0.0.1:61616")
        server = new ActiveMQServerImpl(config)
        server.start()
    }

    void 'is server active'() {
        expect:
        server.active
    }

}
Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
maun
  • 134
  • 1
  • 1
  • 13
  • Most test frameworks have hooks to deal with test dependencies. For example, JUnit has the [`@Before` annotation](https://junit.org/junit4/javadoc/latest/org/junit/Before.html). Does Micronaut have anything like that? – Justin Bertram Apr 04 '21 at 03:07
  • Methods setup() and setupSpec() should act the same as JUnit's @Before. As you can see I have been using them but no avail. – maun Apr 07 '21 at 05:53

0 Answers0