Using NUnit and Unity I have a base class for tests:
[TestFixture]
public class TestBase
{
private string m_filePath = "UnitTest\\response.json";
protected static Event m_current;
protected static Event m_expired;
protected LoginResponse m_response;
public static IEnumerable<TestCaseData> TestRunning
{
get
{
yield return new TestCaseData(m_expired, false);
yield return new TestCaseData(m_current, true);
}
}
[OneTimeSetUp]
public virtual void SetUp()
{
string path = System.IO.Path.Combine(Application.dataPath, m_filePath);
string txt = File.ReadAllText(path);
m_response = JsonFx.Json.JsonReader.Deserialize<LoginResponse>(txt);
m_expired = m_response.events[0];
m_current = m_response.events[1];
}
protected class LoginResponse
{
public List<Event> events;
}
}
I then have a TestCaseSource in a sub class that uses the TestRunning collection and it will fail on first run of the tests after recompiling. If I run the tests again, they pass. The first object comes null in the tests.
The sub class does not have a Setup so it is not preventing the call.