I'm trying to develope an automated regression test framework as unit tests. So I use ordered test to combine the different test steps and combine them in an easy to use way. For configuration purposes i wanna use the runsettings file, especially the TestRunParameters. This works without any errors but only while executing each test by itself. If i execute the tests using the orderedtest, the TestContext object I use to get access to the TestRunParameters doesn't contain them anymore. I debuged the object while testing the method directly and while testing it with ordered tests as well. In the first scenario the object has the needed Properties but when executing the tests as orderedtest the object looks total different. Is there a majore difference between these two types of execution?
The different TestContext objects:
Execution as single test picture
Execution as ordered test picture
The error I get is the following:
Ergebnis StackTrace: at Regression.FileSystem.FileSystemTestInitializer(TestContext context) in \FileSystem.cs:line 18
Ergebnis Meldung: Class Initialization method Regression.FileSystemTestInitializer threw exception. System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object..
The code i execute to test and to load the settings is the follwing:
namespace Regression
{
[TestClass]
public class FileSystem
{
private static Logger logger = LogManager.GetCurrentClassLogger();
private static Dictionary<String, String> runSettings = new Dictionary<String, String>();
[ClassInitialize]
public static void FileSystemTestInitializer(TestContext context)
{
runSettings.Add("scenarioName", context.Properties["scenarioName"].ToString());
runSettings.Add("testRootDir", context.Properties["testRootDir"].ToString());
}
[TestMethod]
public void Action_FileSystem_CleanUp()
{
DirectoryInfo dir = new DirectoryInfo(runSettings["testRootDir"] + runSettings["scenarioName"] + @"\testdata\");
foreach(FileInfo file in dir.GetFiles())
{
file.Delete();
}
foreach (DirectoryInfo childDir in dir.GetDirectories())
{
childDir.Delete(true);
}
DirectoryCopy(runSettings["testRootDir"] + runSettings["scenarioName"] + @"\testdata_backup\", runSettings["testRootDir"] + runSettings["scenarioName"] + @"\testdata\", true);
}
The error comes up on line 11 which is the following:
runSettings.Add("scenarioName", context.Properties["scenarioName"].ToString());
The runsettings file which is included into the test execution of visual studio:
<RunSettings>
<!-- Parameters used by tests at runtime -->
<TestRunParameters>
<Parameter name="scenarioName" value="FileSystem_SharePointOnline_Unidirectional"/>
<Parameter name="testRootDir" value="C:\testfiles\"/>
</TestRunParameters>
</RunSettings>