mardi 16 mars 2021

How to use different static content in unit tests?

I' writing tests in java using JUnit. I've tried something like this (simplified):

public class Main() {

    static int a = 0; 

    public static void main(String[] args) {
        a++;
        System.out.println(a); 
    }
}

public class TestA() {
    @Test
    public void test() {
        Main.main(null);
    }
}

public class TestB() {
    @Test
    public void test() {
        Main.main(null);
    }
}

@RunWith(Suite.class)
@Suite.SuiteClasses({
    TestA.class,
    TestB.class
})
public class All { }

I want my test to be run with static content individual for each test. Is it possible to achieve this behaviours?

Aucun commentaire:

Enregistrer un commentaire