开发者

unit testing priority, tools, metrics

Imagine that we have 1000 functions in our program. Do we need to test all of them?

Can we give some priorities 开发者_JAVA技巧to the functions and can we test some of them after that but not all?

To do this which tools and metrics can we use?


It's best to test everything that isn't obviously ok, skipping just trivial things like getters and setters.

But you might want to measure cyclomatic complexity and worry more about the more complex functions.


Do we need to test all of them?

No. To start with it would be worth following the bugs. Every new bug should end with at least one unit test demonstrating it. Ideally however you would want to retrofit a reasonable automated test suite. Crap4J and Clover can give you an idea on where to start. Clover has its Project Risks and Quick Wins clouds (basically views on cyclomatic complexity and test coverage) which will give some guidance on what should be testing and what will help keep the moral up.


In an ideal world, you will have multiple Unit Tests for each method (or function) in your solution. In reality, this usually doesn't happen, especially when working on existing systems.

There are no automated ways to prioritize which methods you should unit test since every software solution is different. I would focus on methods and classes that are the core of your solution, and try to get as much unit test coverage on those methods. Then focus on the other parts of your code.

Unit testing tools vary based on your language and environment. Visual Studio includes basic unit testing, additionally there is NUnit for .NET testing. For Java there is JUnit.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜