c# - Unit test a function -
c# - Unit test a function -
i got intersting question while writing unit test.
can test function while using function in test code?
for example,
if have list<int>
class has function called add()
.
i want test target list object 2 int inside: 1 , 2. add together 3rd number: 3, , want assert number added. wrote:
public void testmethod() { //initialize list<int> list = new list<int>(); list.add(1); list.add(2); //do operation list.add(3); assert.istrue(list.contains(3)); }
however, above test case, trying test target function: add(), uses add() initialize. thinking corelationship may result in problem under conditions, speaking...
is there test thoery saying cannot this?
thanks!
functions may require more 1 test. in case, have function tested single add()
, , 1 have above. long both pass, can (reasonably) confident results solid. if first test fails, though, result of sec test should ignored.
ideally, though, you'd have access internal state of testing, , hence provide different way of setting intial conditions didn't involve calling function under test.
c# visual-studio unit-testing
Comments
Post a Comment