I am trying to build a report showing the main differences between MsTest and xUnit and I am reading around but plus I am also trying myself things. One of the point reported everywhere as main difference between the 2 frameworks is that MsTest creates one only instance of the class and shares it with all the tests contained, while instead xUnit created a new instance for every test. So I tried myself out of curiosity and demo purposes to show this with MsTest:
[TestClass]
public class UnitTest1
{
public UnitTest1()
{
Debug.WriteLine("Constructor");
}
[TestInitialize]
public void TestInitialize()
{
Debug.WriteLine("Initialize");
}
[TestMethod]
public void TestMethod1()
{
Debug.WriteLine("Test1");
}
[TestMethod]
public void TestMethod2()
{
Debug.WriteLine("Test2");
}
[TestCleanup]
public void TestCleanup()
{
Debug.WriteLine("Cleanup");
}
}
Output:
Constructor
Initialize
Test1
Cleanup
Constructor
Initialize
Test2
Cleanup
So the constructor is running for every test! Meaning that there is actually one instance of the class created for every test also in MsTest! Am I missing something?
Aucun commentaire:
Enregistrer un commentaire