Resetting static fields for JUnit tests

后端 未结 3 457
迷失自我
迷失自我 2021-01-11 15:25

I have a set of JUnit tests which call the main method on a Java program, passes in args and checks the output. That\'s fine.

However, if the program I am testing ha

3条回答
  •  孤独总比滥情好
    2021-01-11 15:56

    You should explicitly initialize any static state within your test classes, usually this is done in methods annotated @Before or @BeforeClass

    This is a reason, among others, why having a lot of static dependencies in an application is a bad idea for testing. That's why many people encourage stateless programming.

提交回复
热议问题