NUnit Test Run Order

I just want to point out that while most of the responders assumed these were unit tests, the question did not specify that they were. nUnit is a great tool that can be used for a variety of testing situations. I can see appropriate reasons for wanting to control test order. In those situations I … Read more

NUnit’s Assert.Equals throws exception “Assert.Equals should not be used for assertions”

Assert is a static class inheriting from System.Object, as all classes do implicitly in C#. System.Object implements the following method: static bool Equals(object a, object b) The methods on Assert which are intended for equality comparison are the Assert.AreEqual() methods. Therefore, calling the Object.Equals() method through the Assert class in a unit test is certainly … Read more

Does MSTest have an equivalent to NUnit’s TestCase?

Microsoft recently announced “MSTest V2” (see blog-article). This allows you to consistently (desktop, UWP, …) use the DataRow-attribute! [TestClass] public class StringFormatUtilsTest { [DataTestMethod] [DataRow(“tttt”, “”)] [DataRow(“”, “”)] [DataRow(“t3a4b5”, “345”)] [DataRow(“3&5*”, “35”)] [DataRow(“123”, “123”)] public void StripNonNumeric(string before, string expected) { string actual = FormatUtils.StripNonNumeric(before); Assert.AreEqual(expected, actual); } } Again, Visual Studio Express’ Test Explorer … Read more

Compare equality between two objects in NUnit

Do not override Equals just for testing purposes. It’s tedious and affects domain logic. Instead, Use JSON to compare the object’s data No additional logic on your objects. No extra tasks for testing. Just use this simple method: public static void AreEqualByJson(object expected, object actual) { var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); var expectedJson = serializer.Serialize(expected); … Read more

Use NUnit Assert.Throws method or ExpectedException attribute?

The main difference is: ExpectedException() attribute makes test passed if exception occurs in any place in the test method. The usage of Assert.Throws() allows to specify exact place of the code where exception is expected. NUnit 3.0 drops official support for ExpectedException altogether. So, I definitely prefer to use Assert.Throws() method rather than ExpectedException() attribute.

NUnit vs. xUnit

At the time of writing this answer, the latest NUnit version is v3.5 and xUnit.net is v2.1. Both frameworks are awesome, and they both support parallel test running (in a different way though). NUnit has been around since 2002, it’s widely used, well documented and has a large community, whereas xUnit.net is more modern, more … Read more

How can we run a test method with multiple parameters in MSTest?

EDIT 4: Looks like this is completed in MSTest V2 June 17, 2016: https://blogs.msdn.microsoft.com/visualstudioalm/2016/06/17/taking-the-mstest-framework-forward-with-mstest-v2/ Original Answer: As of about a week ago in Visual Studio 2012 Update 1 something similar is now possible: [DataTestMethod] [DataRow(12,3,4)] [DataRow(12,2,6)] [DataRow(12,4,3)] public void DivideTest(int n, int d, int q) { Assert.AreEqual( q, n / d ); } EDIT: It … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)