Ejemplo n.º 1
0
        public void ExpandTestcases(string fileName)
        {
            string testOutput = Path.Combine(TestSupport.CreatedFilesDirectory, fileName + ".Output.txt");

            string        source = Path.Combine(TestSupport.TestFilesDirectory, fileName);
            TestCasesRoot tcr    = new TestCasesRoot();

            tcr.Load(source);

            var             statistics = tcr.CalculateStatistics();
            ExpandTestCases expand     = new ExpandTestCases();
            var             result     = expand.Expand(tcr);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("TestCases");
            foreach (TestCase tc in tcr.TestCases)
            {
                DumpTestCase(sb, tc);
                sb.AppendLine();
            }
            sb.AppendLine("expanded TestCases");
            foreach (ITestCase tc in result)
            {
                DumpTestCase(sb, tc);
                sb.AppendLine();
            }
            sb.AppendFormat("calculated {0,5}  expandCount {1,5}", statistics.CoveredTestCases, result.Count);

            File.WriteAllText(testOutput, sb.ToString());
            //ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", testOutput);
            //Process.Start(info);
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(testOutput)));
            Assert.That(statistics.CoveredTestCases == result.Count);
        }
Ejemplo n.º 2
0
        public void CalculateCoverage(string fileName, long expectedCombinations, long expectedUniqueTestCases, double minExpectedCoverage, double maxExpectedCoverage)
        {
            string testSettingPath = Path.Combine(TestSupport.CreatedFilesDirectory, "TestSetting.txt");

            string        source = Path.Combine(TestSupport.TestFilesDirectory, fileName);
            TestCasesRoot tcr    = new TestCasesRoot();

            tcr.Load(source);
            Statistics stat = tcr.CalculateStatistics();

            for (int idx = 0; idx < tcr.TestCases.Count; idx++)
            {
                File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, tcr.TestCases[idx]));
            }
            File.AppendAllText(testSettingPath, Environment.NewLine + Environment.NewLine);

            ExpandTestCases expand            = new ExpandTestCases();
            var             expandedTestCases = expand.Expand(tcr);

            foreach (TestCase expandedTestCase in expandedTestCases)
            {
                File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, expandedTestCase));
            }

            //ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", testSettingPath);
            //Process.Start(info);

            Assert.That(stat.Coverage >= minExpectedCoverage);
            Assert.That(stat.Coverage <= maxExpectedCoverage);
            Assert.That(stat.CoveredTestCases == expectedUniqueTestCases);
            Assert.That(stat.PossibleCombinations == expectedCombinations);
        }
Ejemplo n.º 3
0
        public void CalculateUniqueTestCasesWithDontCare(int id, int[] values, int expectedCombinations, int expectedCoveredTestCases, double expectedCovarage)
        {
            string        testOutputPath  = Path.Combine(TestSupport.CreatedFilesDirectory, "TestOutput.txt");
            string        testSettingPath = Path.Combine(TestSupport.CreatedFilesDirectory, "TestSetting.txt");
            TestCasesRoot tcr             = new TestCasesRoot();

            List <List <ValueObject> > listOfValueLists = new List <List <ValueObject> >();

            var enum1 = TestCasesRoot.CreateSampleEnum("enum1", 4, 0, 0, 3);
            var enum2 = TestCasesRoot.CreateSampleEnum("enum2", 4, 0, 0, 3);
            var enum3 = TestCasesRoot.CreateSampleEnum("enum3", 6, 0, 0, 5);

            tcr.Conditions.Add(ConditionObject.Create("name", enum1));
            tcr.Conditions.Add(ConditionObject.Create("name", enum2));
            tcr.Conditions.Add(ConditionObject.Create("name", enum3));

            for (int idx1 = 0; idx1 < 3; idx1++)
            {
                for (int idx2 = 0; idx2 < 4; idx2++)
                {
                    for (int idx3 = 0; idx3 < 6; idx3++)
                    {
                        listOfValueLists.Add(new List <ValueObject>()
                        {
                            new ValueObject(enum1, idx1), new ValueObject(enum2, idx2), new ValueObject(enum3, idx3),
                        });
                    }
                }
            }

            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 5),
            });

            for (int idx = 0; idx < listOfValueLists.Count; idx++)
            {
                List <ValueObject> condList = listOfValueLists[idx];
                File.AppendAllText(testOutputPath, String.Format("{0:d2} {1} {2} {3}" + Environment.NewLine, idx, condList[0].SelectedValue.ToTestString(), condList[1].SelectedValue.ToTestString(), condList[2].SelectedValue.ToTestString()));
            }

            for (int idx = 0; idx < values.Length; idx++)
            {
                //TestCase tc = new TestCase(String.Format("tc {0:d2}", idx), listOfValueLists[values[idx]], new List<ValueObject>());
                //tcr.TestCases.Add(tc);
                TestCase tc = tcr.InsertTestCase();
                tc.SetValues(tcr, listOfValueLists[values[idx]], new List <ValueObject>());
                //File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, tc));
            }
            Statistics stat = tcr.CalculateStatistics();

            for (int idx = 0; idx < tcr.TestCases.Count; idx++)
            {
                File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, tcr.TestCases[idx]));
            }

            File.AppendAllText(testSettingPath, Environment.NewLine + Environment.NewLine);

            ExpandTestCases expand     = new ExpandTestCases();
            var             resultList = expand.Expand(tcr);

            foreach (TestCase testCase in resultList)
            {
                File.AppendAllText(testSettingPath, String.Format("{0}" + Environment.NewLine, testCase));
            }

            Assert.That(stat.CoveredTestCases == expectedCoveredTestCases);
            Assert.That(stat.PossibleCombinations == expectedCombinations);
            Assert.That(stat.Coverage.Equals(expectedCovarage));
        }