I'm new to unit testing and I'd like to know how is this, I guess typical, problem usually solved:
I have protected method that I'd like to test. I've overriden the tested class with the test class, but the tested class has constructor with 4 arguments and no default constructor. In which part of the test class you add a call to the base (4 args) constructor? I've tried in [SetUp]
method but I get Use of keyword 'base' is not valid in this context
error.
I thought that this simple case is self explaining, but here's the example:
public class A
{
protected Class1 obj1;
protected Class2 obj2;
protected Class3 obj3;
protected Class4 obj4;
public A(Class1 obj1, Class2 obj2, Class3 obj3, Class4 obj4)
{
this.obj1 = obj1;
this.obj2 = obj2;
this.obj3 = obj3;
this.obj4 = obj4;
}
protected virtual void MethodA()
{
//some logic
}
}
[TestFixture]
public class ATests : A
{
[SetUp]
public void SetUp()
{
this.obj1 = Substitute.For<Class1>();
this.obj2 = Substitute.For<Class2>();
this.obj3 = Substitute.For<Class3>();
this.obj4 = Substitute.For<Class4>();
//this line below doesn't compile with the `Use of keyword 'base' is not valid in this context` error.
base(obj1, obj2, obj3, obj4);
}
[Test]
public void MethodA_test()
{
//test MethodA logic
}
}