开发者

JUnit - what are its strengths and weaknesses

I'm wondering what are the strengths and weaknesses of using JUnit for code 开发者_开发百科testing? For example, I don't believe it is good for testing concurrency. Any input would be appreciated. Thanks


Testing concurrent code is hard, no matter what you choose.

TestNG has a mechanism for creating multiple threads and running them in a concurrency test. I believe it'd be possible to create a bunch of FutureTasks in a JUnit test to exercise a method. It's just not supported in JUnit 4.

The strengths? Here are a few:

  1. Separates test code from production code.
  2. Makes it possible to run a suite of tests for an application all at once.
  3. Support in Ant, Maven, and IDEs like IntelliJ and Eclipse.
  4. Has become part of the thinking in Test Driven Development and agile techniques.


JUnit has two strengths:

  1. It works well enough. Moreover, like Perl, it makes the easy things easy and the hard things possible. We have test runners that fit into the JUnit framework but actually do static analysis using the ASM bytecode library.
  2. It's ubiquitous. Everyone knows it, every tool supports it, you can find most answers on the web.

Testing concurrent code is possible in JUnit, but it doesn't provide any particular support for it. You have to manage your threads and arrange interleaving scenarios yourself.

That said, I believe there are tools out there, and if you adopt JUnit, you'll likely find that is the expected scenario from test helpers like hamcrest matchers.


Just a note for people searching concurrency - there is a unit test framework designed to test concurrency (something-Unit). A Google search is not finding it for me, but I know it exists, read about it recently.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜