C # comparison of common unit test frameworks: XUnit, NUnit, and Visual Studio (MSTest ),
People who have done unit tests probably know the above test frameworks, but I have been curious about their differences, then I found a good article that clearly explained the biggest differences between these frameworks.
Address here: http://www.tuicool.com/articles/F3eEn2j
In short, XUnit and NUnit are very similar except for the characteristics of annotation test classes and methods. The biggest difference between them and MSTest is the additional value passing test, as shown below:
1 [TestCase(1)] 2 [TestCase(2)] 3 [TestCase(3)] 4 [TestCase(4)] 5 public void FireMultipleTimes(int fireCount) 6 { 7 Bug bug = new Bug(); 8 Raygun gun = new Raygun(); 9 10 for(int i = 0; i < fireCount; i++) 11 {12 gun.FireAt(bug);13 }14 15 if (fireCount >= 3) 16 {17 Assert.IsFalse(gun.HasAmmo());18 }19 else 20 {21 Assert.IsTrue(gun.HasAmmo());22 }23 }
The above is NUnit, and XNunit has a similar method. This article is very suitable for beginners of unit testing.
However, open-source frameworks, including Abp, use XUnit or NUnit.
According to an online survey, there are still many negative comments on MSTest. The main problem is that MSTest is not flexible enough to run unit tests on non-Microsoft platforms, however. today, Net Core is becoming increasingly mature, and I think it is no longer a problem. The following MSTest test code:
1 [TestClass] 2 public class UnitTest1 3 { 4 [DataTestMethod] 5 [DataRow(1, 2, 2)] 6 [DataRow(2, 3, 5)] 7 [DataRow(3, 5, 8)] 8 public void AdditionTest(int a, int b, int result) 9 {10 Assert.AreEqual(result, a + b);11 }12 }
Now, almost none of these frameworks are bad. I can see a comment in StackOverflow that I agree:
In fact, you don't have to worry so much about it. You can choose the best option. MSTest is the best integration for Vs, and it is easy to use. If one day you encounter something that cannot be solved, switching to other frameworks is also very simple, just the next Nuget package, just change the features.
Reprinted link: https://www.cnblogs.com/RobotZero/p/6732728.html