Click here to Skip to main content
12,350,831 members (41,989 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# testing NUnit
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 4:40am
Edited 28-Nov-12 11:05am
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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 28 Nov 2012
Copyright © CodeProject, 1999-2016
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