0

I have setup an embedded mongo via flapdoodle (de.flapdoodle.embed). Quite a lot of mongo operations hence i would like to run all of them as a suite and setup the mongo just once in testsuite. Now when i run the test cases via mvn install , it seems to run the test cases individually.

Is there a way to run test cases only from suite and not as a class.

Ravisha
  • 3,261
  • 9
  • 39
  • 66

1 Answers1

1

baeldung.com describes the use of JUnit 5 Tags, which are very well suited for your case.

You can mark tests with two different tags:

@Test
@Tag("MyMongoTests")
public void testThatThisHappensWhenThatHappens() {
}

@Test
@Tag("MyTestsWithoutMongo")
public void testThatItDoesNotHappen() {
}

And execute either set in a suite, e.g.

@IncludeTags("MyMongoTests")
public class MyMongoTestSuite {
}

In your case, the tests could be categorized by whether Mongo is in the application context or not. So, theoretically, it might be possible to create a JUnit 5 Extension to add the tag. That would be the more complex solution though.

Darkwyng
  • 130
  • 1
  • 7
  • 1
    Perhaps I am missing something, I want the tests to be executed only from the suite. The Testcases class should not be executed on its own – Ravisha Jan 30 '20 at 03:04