I'm trying to switch over an existing Selenium solution to use NUnit due to it's support of parallelization of tests within the same class. The problem I'm having is that it doesn't seem to be using the selected .runsettings file, despite the fact that it's supported by NUnit. By this, I mean that TestContext.Parameters.Count is always 0, and it doesn't store results in the path specified in the <ResultDirectory> node of my .runsettings file.
I've looked over the documentation and the reference to AdapterSettings (which has logic for parsing the .runsettings file) and I can't f figure out why my TestContext.Paramaters are never populated in my test when I use a .runsettings file.
I created a bare-bones test solution just as a sanity check and POC and it's still not populating.
I have
-NUnit 3.7.1
-NUnit3TestAdapter 3.7.0
-VisualStudio Professional 2017
My .runsettings file is:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Parameters used by tests at runtime -->
<TestRunParameters>
<Parameter name ="testParameter1" value="value1" />
<Parameter name ="testParameter2" value="value2" />
</TestRunParameters>
</RunSettings>
All I'm trying to do in the test:
using System;
using NUnit.Framework;
namespace ClassLibrary1
{
[TestFixture]
public class UnitTestClass1
{
[Test]
[Parallelizable(ParallelScope.All)]
public void Class1TestMethod1()
{
// Below always returns 0
Console.WriteLine(TestContext.Parameters.Count);
// Below returns null
Console.WriteLine(TestContext.Parameters["testParameter1"]);
}
}
}
I could really use some other suggestions on how to troubleshoot. We use .runsettings files extensively for our test suite with the built-in Visual Studio Unit Testing tools (and with vstest.console.exe), so I'm pretty confident I'm using it correctly.
Update:
I replaced all references to Visual Studios test attributes in my actual test solution to use NUnits attributes. Now I'm getting the parameters! However, that leaves me still baffled as to why it doesn't work in my other bare-bones solution (with files shown above).
I really only care about my real solution obviously, but I still want to understand why it's not working in my dummy solution.
Also - I still am not sure where to find the TestResultDirectory path in NUnit.