Quarkus unit tests exclude class

Viewed 1024

I am moving from Thorntail to Quarkus. In my tests I used to create a @deployment method in which I put only what was needed by the tests. In particular I didn't put a Class having a @Startup annotation (because I didn't want to test that ...). When I moved to QUARKUS, I suppress de @deployment static method, then when I launch the tests @Startup is ... started and a lot of bad things happen which prevent me from testing what I want to test (well, it crashes because it tries to connect to services which are not available).

So the question is : is there a way to exclude some package or class when lauching a test with quarkusTest ?

1 Answers

I finally created a class :

@ApplicationScoped
public class ApplicationLifeCycle {
private final Logger log = Logger.getLogger(getClass());

@Inject
Startup startup;

void onStart(@Observes StartupEvent ev) {
    log.info("The application is starting with profile " + ProfileManager.getActiveProfile());
    if (!ProfileManager.getActiveProfile().equalsIgnoreCase("test")) {
        startup.getModel();
    }
}

void onStop(@Observes ShutdownEvent ev) {
    log.info("The application is stopping...");
    startup.stopMQ();
}
}

A bit ugly isn't it ? Is there a better way to do it ?

Related