devonfw / devon4j

devonfw Java stack - create enterprise-grade business apps in Java safe and fast
Apache License 2.0
83 stars 87 forks source link

BaseTest.isInitialSetup() broken #366

Closed hohwille closed 3 years ago

hohwille commented 3 years ago

With BaseTest we are providing a base-class for JUnit tests. It provides a feature that allows to determine if the test-class runs for the first time or you are in a sub-sequent run of an additional test method within the same JUnit test class.

Unfortunately this feature seem to have been broken from the start and never worked. Only now with PR #365 we noticed that there is a fundamental bug that is needed to be fixed asap. Sorry for that and thanks for the feedback via PR #365 so we notice and can fix.

hohwille commented 3 years ago

PoC: I have created two such classes (2nd identical with 2 instead of 1):

public class BaseTestState1Test extends BaseTest {
  @Override
  protected void doSetUp() {
    System.out.println("BaseTestState1Test - isInitialSetup() = " + isInitialSetup());
    super.doSetUp();
  }

  @Test
  public void test1() {
    System.out.println("BaseTestState1Test - test1");
  }

  @Test
  public void test2() {
    System.out.println("BaseTestState1Test - test2");
  }
}

Running JUnits gives me:

BaseTestState1Test - isInitialSetup() = false
BaseTestState1Test - test1
BaseTestState1Test - isInitialSetup() = true
BaseTestState1Test - test2
BaseTestState2Test - isInitialSetup() = true
BaseTestState2Test - test1
BaseTestState2Test - isInitialSetup() = true
BaseTestState2Test - test2

This obviously confirms the bug:

hohwille commented 3 years ago

Now, it is trivial to fix this and with that fix I get:

BaseTestState1Test - isInitialSetup() = true
BaseTestState1Test - test1
BaseTestState1Test - isInitialSetup() = false
BaseTestState1Test - test2
BaseTestState2Test - isInitialSetup() = true
BaseTestState2Test - test1
BaseTestState2Test - isInitialSetup() = false
BaseTestState2Test - test2