Salesforce Apex Testing Using static blocks


While you can use the @testSetup annotation to designate a method to be run before tests are executed, this method will usually only be run once. If you need code to be run before each test, you can use a static block:

public class MyTest {
  static {
    // code here will be run before each test is executed