FilesExistStep

Feb 26, 2010 at 10:34 AM

Hello,

I start a discussion "reliability of automated test runs" where I touch on the topic FilesExistStep. This test steps works other like expected. I do not think that it is helpful to wait a specific time and then look only one time in the target directory. I think it is more helpful if you have a FilesExistStep that have a two conditions in a loop. The first one is that expected file number and the second one is the time how long the test step should observe the directory. In case of suspended messages you never enrich the expected file number. In such a case you need a further condition that interrupt the test step.

public void Execute(XmlNode testConfig, Context context)
        {
            string directory = context.ReadConfigAsString(testConfig, "TagetDirecotry");
            string filter = context.ReadConfigAsString(testConfig, "SearchPattern");
            int expectedFiles = context.ReadConfigAsInt32(testConfig, "ExpectedFilesInTarget");
            int foundFiles=0;
            DateTime observationFinishedAt = DateTime.Now.Add(TimeSpan.Parse(context.ReadConfigAsString(testConfig, "Duration")));
            
            try
            {

                while (foundFiles < expectedFiles || DateTime.Now < observationFinishedAt )
                {
                    foundFiles = Directory.GetFiles(directory, filter).Length;
                    Thread.Sleep(1500);
                }
                if (foundFiles == expectedFiles)
                {
                    context.LogInfo("FilesExistStep found: \"{0}\" files", foundFiles);
                }
                else
                {
                    context.LogInfo("FilesExistStep interrupted by exceeding duration ({0})", context.ReadConfigAsString(testConfig, "Duration"));
                }foundFiles); 
            }
            catch(Exception ex)
            {
                context.LogException(ex);
            }
            
        }
You can better control the directory during BizTalk is sending its messages out. If you want then you can add the variable for the interval as well.
This is my understanding of the FilesExistStep. I need this test step as condition if the test run is reliable or not.
With kind regards

Stephan