c# - Could some one check for me if my unit test for the FillUpWater is correct -


could tell me correct unit test fillupcontainer()?

namespace coffeemaker {     [testclass()]     public class watercontainer     {         //private watercontainer waterc;          watercontainer waterc = new watercontainer(0);         int level = waterc.level;          [testmethod()]         public void fillupwatertest()          {                                                   if (waterc.level == 0)             {                 bool result;                result = waterc.fillupwater();                             }             level.equals(5);         }     } } 

no, it's not. level.equals(5) not assertion, it's expression, result of throw away not assigning anything.

a better test might this:

[testclass()] public class watercontainer {             [testmethod()]     public void whenwatercontainerisempty_fillingitup_causescorrectwaterlevel()      {                                               // arrange         watercontainer water = new watercontainer(0);         // act         water.fillupwater();         // assert         assert.areequal(5, water.level);     } } 

notice method name describes what's being tested, , test self-contained (all local variables).

the assert statement cause test fail if water level not correct.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -