Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# NUnit test
Hi,
I'm new to testing
For example I have a test (test1) that test if getFoo() return something and i have a more complex test (test2) that use one or more time getFoo()
I want the test2 to not start if test1 fails or at least to fail automatically without start testing.
 
I searched the documentation on Nunit for some attribute like [Require(someothertest)] but i couldn't find anything.
 

Sorry for my broken english, hope the question is understandable
 
I'm not doing this
test1(){
    //some test code here
    test2();
}
 
but I'm doing this
 
test1(){
    Assert(obj.getFoo()>0);
}
test2(){
    int testValue=obj.getFoo();
    Assert(obj.doSomething(testValue)>=0);
}
this is just an example
but as can you see test2 use obj.getFoo(), so if test1 fails i know getFoo() don't work correctly but getFoo may return a value that make test2 pass anyway, so I want that if test1 fails, test2 must not be tested or must automatically fail since it's not an attendible test
 
I hope i explained myself a little better Smile | :)
Posted 24-Nov-12 5:40am
Edited 28-Nov-12 12:05pm
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

First of all...its a bad practice to call a test method in another test method.There should not be any dependencies among the test methods
Those should be able to execute independently.
 
If you want to do it, probably one has to put check before Assert
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 505
1 Maciej Los 325
2 Richard MacCutchan 265
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411028.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100