Hi,
I'm trying NCrunch at the moment for my company and I hit an error. It seems that when you having an inherited test class, the TestInitialize method from the inherited class is being run for test methods in the base class.
As an example I've created the following code:
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace UnitTestProject1
{
[TestClass]
public class BaseTest
{
protected CalcBuilder builder;
[TestInitialize]
public void TestInitialize()
{
builder = new CalcBuilder().SetX(1)
.SetY(1);
}
[TestMethod]
public void SumShouldBeTwo()
{
Assert.AreEqual(2, builder.Make().Sum());
}
}
public class CalcBuilder
{
int x, y;
public CalcBuilder SetX(int x)
{
this.x = x;
return this;
}
public CalcBuilder SetY(int y)
{
this.y = y;
return this;
}
public Calc Make()
{
return new Calc(this.x, this.y);
}
}
public class Calc
{
private int x, y;
public Calc(int x, int y)
{
this.x = x;
this.y = y;
}
public int Sum()
{
return x + y;
}
}
}
The above code runs without any problem, all the NCrunch indications lights are green. But when I add the following class, the test method is failing in NCrunch:
[TestClass]
public class BaseTest2 : BaseTest
{
[TestInitialize]
public void NewSetup()
{
builder = builder.SetX(2)
.SetY(2);
}
}
When I run the test method in ReSharper or with the Visual Studio test runner, the test is passing. But the NCrunch indication lights are red :(
Is this a bug?
Thank you in advance.
Rick Neeft