1

I am trying to executes some tests using JUnit 5 Test Suite. Based on the documentation I found, I used @RunWith and @SelectPackages (from the dependency junit-platform-runner).

Before I started the tests defined in the @SelectPackages, I wanted to load some properties file in such a setup method. I tried using @BeforeAll, @ClassRule and @Rule, but those setup methods are only called in any test methods in the annotated class (RemoteTests). But the setup methods are not called before the executions of the test classes defined in the @SelectPackages (com.test.packages).

@RunWith(JUnitPlatform.class)
@SelectPackages("com.test.packages") 
public class RemoteTests {
    @Rule // I tried also @ClassRule and @BeforeAll here
    public void setup() {
        PropertiesLoader.loadProperties("remote.properties");
    }
}

Are there any setup annotations for my purpose?

Druckles
  • 3,161
  • 2
  • 41
  • 65
Heru Salim
  • 11
  • 1
  • JUnit5 has no `@RunWith` (it has `@ExtendWith`) nor `@Rule`. Maybe you are mixing annotations with JUnit4? – pirho Nov 03 '20 at 16:34
  • Thanks for your reply. You might be right, because the dependency tree contains junit 4 also. But I only followed the instruction in several websites, such as https://www.baeldung.com/junit-5 (chapter 7. Test Suites). Does @ExtendWith works exactly as @RunWith? Or is there any possibilities to start a test suite in JUnit 5? – Heru Salim Nov 05 '20 at 13:04
  • See [this](https://www.baeldung.com/junit-5-runwith) chapter 4. So are you running JUnit4 tests in JUnit5. Or vice versa. – pirho Nov 05 '20 at 13:46
  • Hi pirho, thanks. For me it is preferable to run everything in JUnit5, but I cannot find any information on how to have TestSuite it in a pure JUnit5 environment. Anyway in worst case, it is enough for me to use JUnit4, but I could not make it to run the tests with some setup method, where I would like some properties file before executing the tests. In the given example from your link, there is not shown how to put some setup method before the tests. I have tried using `@BeforeClass`, `@ClassRule`, `@BeforeAll`, but nothing helped :( – Heru Salim Nov 06 '20 at 14:11

0 Answers0