NUnit comparing two lists

If you’re comparing two lists, you should use test using collection constraints. Assert.That(actual, Is.EquivalentTo(expected)); Also, in your classes, you will need to override the Equals method, otherwise like gleng stated, the items in the list are still going to be compared based on reference. Simple override example: public class Example { public int ID { … Read more

Evaluate if two doubles are equal based on a given precision, not within a certain fixed tolerance

From msdn: By default, a Double value contains 15 decimal digits of precision, although a maximum of 17 digits is maintained internally. Let’s assume 15, then. So, we could say that we want the tolerance to be to the same degree. How many precise figures do we have after the decimal point? We need to … Read more

JetBrains Resharper 9 Ultimate Test Runner error: NUnit.Core.UnsupportedFrameworkException: Skipped loading assembly {MyAssembly}

As mentioned in the accepted answer, ReSharper 9 does not support NUnit 3. The solution as stated does work (i.e. update to ReSharper 10), however, for those who do not have this option (e.g. licensing), you can downgrade your version of NUnit by following the below steps: Open Nuget Package Manager Console by going to … Read more

Dynamically create tests in NUnit

I’ve found a way that fits my purposes Have one test case, and mark it with the TestCaseSource attribute like so [Test, TestCaseSource(“GetTestCases”)] public void TestFile(string filename) { //do test } Then write the GetTestCases to read all the file names in the directory private static string[] GetTestCases() { return GetAllFilesInCurrentDirectory(); } Then when I … Read more

Is it possible to execute a method before and after all tests in the assembly?

If all your test fixtures are within the same namespace then you can use the [SetUpFixture] attribute to mark a class as the global setup and teardown. You can then put all your login/logout functionality in there. NUNIT 2.x namespace MyNamespace.Tests { using System; using NUnit.Framework; [SetUpFixture] public class TestsSetupClass { [SetUp] public void GlobalSetup() … Read more