-3

In JUnit, why @BeforeClass is marked static? What is the significance in doing so?

And for every xxxTest() method, does Junit creates a new instance of the class? https://martinfowler.com/bliki/JunitNewInstance.html

If yes why so?

ANG
  • 51
  • 8

1 Answers1

3

Did you read any of the JUnit docs?

Straight from the @BeforeClass docs:

Sometimes several tests need to share computationally expensive setup
...
Annotating a public static void no-arg method with @BeforeClass causes it to be run once before any of the test methods in the class.
...

Straight from the @Test docs:

...
To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method.
...

Matt Clark
  • 27,671
  • 19
  • 68
  • 123