Tricks for writing the best unit tests

What are some of the tricks or tools or policies (besides standard unit testing) that you guys use to write better unit tests? For the best, I mean that "covers as much of your code as possible as few tests as possible." I am talking about the things you used, and I saw that your unit tests are improving by the hour, not by the day.

As an example, I tried to try out Pex , and I thought it was really really good. There were tests that I missed, and Pex easily showed me where. Unfortunately, it has a rather restrictive license.

So, what are some other great things you guys use / do?

EDIT: Lots of good answers. I will mark it as the correct answer, which I do not practice now, but I will definitely try, and I hope it will give the best win. Thanks to everyone.

+5
source share
7 answers

In my current project, we use a small generation tool to create skeleton block tests for various objects and accessories, it provides a fairly consistent approach for each unit of work that needs to be tested, and creates a great place for developers to test their implementation (i.e. class unit test is added when other entities and other dependencies are added by default).

(templated) , /- / ( ).

( ) , , .

+2
  • .
  • . .
  • . IOW: , , false true. int? -1,0,1, n, n + 1 ( ). ( Java). 4. . 4b. -. 4c. .
  • . ( Java: Guice - , Spring - , )
  • "Unit" , mockito ( , Java ).
  • Google .
  • . ( 2 - , google - "".)
  • .
  • , ...
+11

(: Test Driven Development). - , . , . . .

, , , . , . -, , .

. - .

+4

, .

+2

, SO, :

,

- , , , .

+1

ruby ​​ script, "" , TDD. script, /usings /, . , , Dark Times.

+1

, , - . , , , . , , . , , , , , , .

, :

void MyClass::UpdateCacheInfo(
    CacheInfo *info)
{
    if (mCacheInfo == info) {
        return;
    }
    info->incrRefCount();
    mCacheInfo->decrRefCount();
    mCacheInfo = info
}

, :

test UpdateCacheInfo_identical_info
test UpdateCacheInfo_increment_new_info_ref_count
test UpdateCacheInfo_decrement_old_info_ref_count
test UpdateCacheInfo_update_mCacheInfo
+1

All Articles