lundi 12 septembre 2016

C# unit tests test context null reference error only while executing ordered test

What am I doing?
I'm working on the automation of regression tests. This should be as easy to use and maintaine as possible and also compatible with Team Services Build Pipeline. After a lot of research I deciced to use Unit Tests to implement a set of cases which represent each an step like "Cleaning up file system". These cases can be combined and ordered using ordered tests which is possible via a really easy to use UI.

Problem
I implemented some cases. These cases use parameters which are stored inside a runsettings file. (This enables the user to change parameters through the build pipeline interface).

 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);
        }

Executing this test manually by select it and run it is successfully. But executing this within an ordered test failes.

If you have another idea how i could accomplish these requirements: Go for it.

Aucun commentaire:

Enregistrer un commentaire