Eric Brandwein
Eric Brandwein

Reputation: 881

More than one method annotated with @Before

Can there be more than one method in a unit test annotated with @Before in junit? If so, which one would be executed first?

Upvotes: 1

Views: 1157

Answers (1)

nickb
nickb

Reputation: 59699

  1. Yes, you can have multiple @Before methods.
  2. Execution order in general is not guaranteed in JUnit, since it depends upon what order your JVM returns the methods in when JUnit reflectively gathers information about your test class. Keeping this in mind, there's no guarantees as to which method runs first, and order should not be relied upon.

Upvotes: 2

Related Questions