I dont have to say very much. The following code sample prints "null", but i expect it to print "test". What is worg here?
import org.junit.BeforeClass;
import org.junit.jupiter.api.Test;
class AcceptanceTest {
private String test;
@BeforeClass
public void setup() {
test = "test";
}
@Test
void test() {
System.out.println(test);
}
}
@BeforeClasssignals that the code is to be executed before class instantiation which only works with static methods (as there is no class context to run them in). In such a method you can also not set a non-static value. You are probably not receiving error messages because you are running it with Jupiter JUnit. The BeforeClass annotation does not even get considered there so the code is never executed.@BeforeEachinstead. Or change your version of JUnit as suggested by the answers below.