JUnit: new instance before invoking each @Test method. What are the benefits?

后端 未结 3 915
暗喜
暗喜 2020-12-03 13:46

Currently, I am reading \"JUnit in action\" book. In this book I found text below:

JUnit creates a new instance of the test class before invoking eac

3条回答
  •  借酒劲吻你
    2020-12-03 14:27

    Keeping the state clean between test methods is useful for unit tests but gets in the way for functional tests, where having dependencies between tests is often necessary (for example, when you are testing web pages using Selenium, it's useful to not bother running tests of a certain page if the tests for the login page failed).

    This was one of the main reasons why I created TestNG, which doesn't instantiate a new class between each method, therefore giving you the choice instead of imposing this decision on you.

    TestNG also supports dependencies of tests, multithread testing, has the notion of groups ("only run the servlet tests") and many more features.

提交回复
热议问题