Login

Login
  • Register
  • VectorDesign blog

    Testing Automation and general Tech Geek stuff

    JUnit Annotations Cheat Sheet

    Posted in Junit on 13 September 2017 by vectordesign

    @Before is executed before each test,

    @BeforeClass runs once before the entire test fixture.

    If your test class has ten tests, @Before code will be executed ten times, but @BeforeClass will be executed only once.

    In general, you use @BeforeClass when multiple tests need to share the same computationally expensive setup code. Establishing a database connection falls into this category. You can move code from @BeforeClass into @Before, but your test run may take longer. Note that the code marked @BeforeClass is run as static initializer, therefore it will run before the class instance of your test fixture is created.

    One thought on "JUnit Annotations Cheat Sheet"