Is it a bad idea to create tests that rely on each other within a test fixture?

Posted by nbolton on Stack Overflow See other posts from Stack Overflow or by nbolton
Published on 2010-06-08T12:52:43Z Indexed on 2010/06/08 13:02 UTC
Read the original article Hit count: 174

Filed under:
|

For example:

// NUnit-like pseudo code (within a TestFixture)

Ctor()
{
 m_globalVar = getFoo();
}

[Test]
Create()
{
 a(m_globalVar)
}

[Test]
Delete()
{
 // depends on Create being run
 b(m_globalVar)
}

… or…

// NUnit-like pseudo code (within a TestFixture)

[Test]
CreateAndDelete()
{
 Foo foo = getFoo(); 
 a(foo);

 // depends on Create being run
 b(foo);
}

… I’m going with the later, and assuming that the answer to my question is:

No, at least not with NUnit, because according to the NUnit manual:

The constructor should not have any side effects, since NUnit may construct the class multiple times in the course of a session.

... also, can I assume it's bad practice in general? Since tests can usually be run separately. So the result of Create may never be cleaned up by Delete.

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about nunit