Esempio n. 1
0
        public void AppendCopyOfTestCaseSampleProjectTest()
        {
            TestCasesRoot tcr = new TestCasesRoot();

            tcr.CreateSampleProject();
            TestUtils.CheckTestCasesAndConditionsAndActions(tcr);
            int testCasesCount = tcr.TestCases.Count;

            for (int tcIdx = 0; tcIdx < testCasesCount; tcIdx++)
            {
                TestCase newTestCase      = tcr.InsertTestCase();
                TestCase templateTestCase = tcr.TestCases[tcIdx];
                tcr.CopyTestCaseSettings(templateTestCase, newTestCase);
            }

            // create and save the sample project
            string savePath = Path.Combine(TestSupport.CreatedFilesDirectory, "SimpleProject.dtc");

            tcr.Save(savePath);
            ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", savePath);

            Process.Start(info);

            for (int tcIdx = 0; tcIdx < testCasesCount; tcIdx++)
            {
                CompareTestCases(tcr, tcIdx, tcIdx + testCasesCount);
            }
        }
Esempio n. 2
0
        public void TestCalculationEnumValues(int count, int defaultIndex, int invalidIndex, int dontCareIndex, int expectedResult)
        {
            var  condition = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", count, defaultIndex, invalidIndex, dontCareIndex));
            long result    = TestCasesRoot.CalculateEnumValuesWithoutDontCareAndInvalid(condition);

            Assert.That(result == expectedResult);
        }
Esempio n. 3
0
        public void CreateAllTestCases(TestCasesRoot tcr, int expectedCount)
        {
            string testResult = Path.Combine(TestSupport.CreatedFilesDirectory, "TestResult.txt");

            long result = tcr.CalculatePossibleCombinations();

            Assert.That(result == expectedCount);

            TestCaseCreator creator = new TestCaseCreator();

            creator.CreateMissingTestCases(tcr);

            List <TestCase> missingTestCases = creator.CreatedTestCases;

            StringBuilder sb = new StringBuilder();

            foreach (TestCase tc in creator.CreatedTestCases)
            {
                sb.AppendLine(TestUtils.TestCaseToString(tc));
            }
            File.WriteAllText(testResult, sb.ToString());
            //Process.Start(testResult);

            Assert.IsTrue(missingTestCases.Count == result);
            foreach (TestCase tc in missingTestCases)
            {
                Assert.IsTrue(tc.Conditions.Count == tcr.Conditions.Count);
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
 public TestCasesRootContainer()
 {
     TestCasesRoot = TestCasesRoot.CreateSimpleTable();
     TestCasesRoot.ActionsBeginChange    += TestCasesRootOnActionsChanged;
     TestCasesRoot.ActionsEndChange      += TestCasesRootOnActionsChanged;
     TestCasesRoot.ConditionsBeginChange += TestCasesRootOnConditionsChanged;
     TestCasesRoot.ConditionsEndChange   += TestCasesRootOnConditionsChanged;
 }
Esempio n. 7
0
        public void CreateAllTestCases1()
        {
            TestCasesRoot tcr = new TestCasesRoot();

            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-1", 4, 0, 0, 3)));

            CreateAllTestCases(tcr, 2);
        }
        public void FirstHtmlContentFromTemplateResourceEmptyProject()
        {
            string        resultPath = Path.Combine(TestSupport.CreatedFilesDirectory, "output.html");
            TestCasesRoot tcRoot     = new TestCasesRoot();
            var           result     = tcRoot.GenerateFromTemplateString(DecisionTableCreator.Templates.Resources.HtmlTemplate);

            File.WriteAllText(resultPath, result.GeneratedContent);
            Assert.That(!result.ErrorListener.ErrorReported);
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(resultPath)));
        }
Esempio n. 9
0
 public DataContainer()
 {
     TestCasesRoot = new TestCasesRoot();
     //TestCasesRoot.CreateTestProject();
     Conditions = TestCasesRoot.ConditionTable;
     Actions    = TestCasesRoot.ActionTable;
     OnStatisticsChanged();
     DirtyObserver = new DirtyObserver(this);
     UpdateTitle();
     DirtyChanged += OnDirtyChanged;
 }
        public void CreateHtmlTableTest()
        {
            string        templPath   = Path.Combine(TestSupport.TestFilesDirectory, "HtmlTemplate.stg");
            string        resultPath  = Path.Combine(TestSupport.CreatedFilesDirectory, "output.htm");
            TestCasesRoot tcRoot      = TestCasesRoot.CreateSimpleTable();
            var           templResult = tcRoot.GenerateFromtemplate(templPath);

            File.WriteAllText(resultPath, templResult.GeneratedContent);
            Assert.That(!templResult.ErrorListener.ErrorReported);
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(resultPath)));
        }
Esempio n. 11
0
        public void CreateAllTestCases4()
        {
            TestCasesRoot tcr = new TestCasesRoot();

            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-1", 4, 0, 0, 3)));
            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-2", 4, 0, 0, 3)));
            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-3", 1, 0, 0, -1)));
            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name-4", 4, 0, 0, -1)));

            CreateAllTestCases(tcr, 2 * 2 * 3);
        }
        internal void Check(TestCasesRoot testCasesRoot)
        {
            Assert.That(testCasesRoot.TestCases.Count == TestCaseContainers.Count);
            Assert.That(testCasesRoot.TestCases.Count == TestCaseContainers.Count);

            var orderedTestCases = testCasesRoot.TestCases.OrderBy(tc => tc.Name).ToArray();

            for (int idx = 0; idx < testCasesRoot.TestCases.Count; idx++)
            {
                TestCase tc = orderedTestCases[idx];
                GetContainerByName(tc.Name).TestCaseConditionValues.Check(tc.Conditions);
                GetContainerByName(tc.Name).TestCaseActionValues.Check(tc.Actions);
            }
        }
        internal void AppendTestCase(TestCase newTestCase, TestCasesRoot testCasesRoot)
        {
            TestCaseContainer cont = new TestCaseContainer();

            cont.Name = newTestCase.Name;
            var selValues = new SelectedValues();

            selValues.Values             = SelectedValue.CreateNew(testCasesRoot.Conditions.Count);
            cont.TestCaseConditionValues = selValues;
            selValues                 = new SelectedValues();
            selValues.Values          = SelectedValue.CreateNew(testCasesRoot.Actions.Count);
            cont.TestCaseActionValues = selValues;
            TestCaseContainers.Add(cont);
        }
Esempio n. 14
0
        public void Save100()
        {
            string        savePath = Path.Combine(TestSupport.CreatedFilesDirectory, "Save.dtc");
            TestCasesRoot root     = TestCasesRoot.CreateSimpleTable();

            root.Save(savePath);

            root.New();

            root.Load(savePath);

            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(savePath)));
            //ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", savePath);
            //Process.Start(info);
        }
Esempio n. 15
0
        public void LoadOldProjectFiles(int idx, string fileName)
        {
            string        loadPath = Path.Combine(TestSupport.TestFilesDirectory, fileName);
            string        savePath = Path.Combine(TestSupport.CreatedFilesDirectory, fileName);
            TestCasesRoot root     = new TestCasesRoot();

            root.Load(loadPath);

            root.Save(savePath);
            // only to view the diffrence
            TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.TestFilesDirectory, Path.GetFileName(savePath));
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(savePath)));
            //ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", savePath);
            //Process.Start(info);
        }
        public void CustomErrorListenerTest(int idx, string fileName, bool errorsExpected)
        {
            string        templatePath = Path.Combine(TestSupport.TestFilesDirectory, fileName);
            string        outputPath   = Path.Combine(TestSupport.CreatedFilesDirectory, "output" + idx + ".txt");
            string        errorsPath   = Path.Combine(TestSupport.CreatedFilesDirectory, "errors" + idx + ".txt");
            TestCasesRoot tcRoot       = TestCasesRoot.CreateSimpleTable();
            var           output       = tcRoot.GenerateFromTemplateString(File.ReadAllText(templatePath));

            Assert.That(output.ErrorListener.ErrorReported == errorsExpected);

            File.WriteAllText(outputPath, output.GeneratedContent);
            File.WriteAllText(errorsPath, output.GetErrorList());
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(outputPath)));
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(errorsPath)));
        }
Esempio n. 17
0
        public void SaveTestCaseDescription()
        {
            string        savePath = Path.Combine(TestSupport.CreatedFilesDirectory, "Save.dtc");
            TestCasesRoot root     = TestCasesRoot.CreateSimpleTable();

            root.TestCases[0].Description = "test description";
            Assert.True(root.TestCases[1].Description == "");
            root.Save(savePath);

            root.New();

            root.Load(savePath);

            Assert.True(root.TestCases[0].Description == "test description");
            Assert.True(root.TestCases[1].Description == "");
        }
 internal void CollectValues(TestCasesRoot testCasesRoot)
 {
     ActionValues    = new List <SelectedValues>();
     ConditionValues = new List <SelectedValues>();
     foreach (ConditionObject condition in testCasesRoot.Conditions)
     {
         var selValues = new SelectedValues();
         selValues.Collect(condition);
         ConditionValues.Add(selValues);
     }
     foreach (ActionObject action in testCasesRoot.Actions)
     {
         var selValues = new SelectedValues();
         selValues.Collect(action);
         ActionValues.Add(selValues);
     }
 }
        internal void Check(TestCasesRoot testCasesRoot)
        {
            Assert.That(testCasesRoot.Conditions.Count == ConditionValues.Count);

            for (int idx = 0; idx < testCasesRoot.Conditions.Count; idx++)
            {
                ConditionObject co = testCasesRoot.Conditions[idx];
                ConditionValues[idx].Check(co);
            }

            Assert.That(testCasesRoot.Actions.Count == ActionValues.Count);

            for (int idx = 0; idx < testCasesRoot.Actions.Count; idx++)
            {
                ActionObject co = testCasesRoot.Actions[idx];
                ActionValues[idx].Check(co);
            }
        }
Esempio n. 20
0
        public void CompareTestCasesTest(int idx1, int idx2, int idx3, int idx4, bool expectedResult)
        {
            var enum1 = TestCasesRoot.CreateSampleEnum("enum1", 4, 0, 0, 3);
            var enum2 = TestCasesRoot.CreateSampleEnum("enum2", 4, 0, 0, 1);
            List <ValueObject> conditions1 = new List <ValueObject>();

            conditions1.Add(new ValueObject(enum1, idx1));
            conditions1.Add(new ValueObject(enum2, idx3));
            List <ValueObject> conditions2 = new List <ValueObject>();

            conditions2.Add(new ValueObject(enum1, idx2));
            conditions2.Add(new ValueObject(enum2, idx4));
            TestCase tc1    = new TestCase("tc1", conditions1, new List <ValueObject>());
            TestCase tc2    = new TestCase("tc2", conditions2, new List <ValueObject>());
            bool     result = tc1.TestSettingIsEqual(tc2);

            Assert.That(result == expectedResult);
        }
Esempio n. 21
0
        public void TestCalculationConditions()
        {
            TestCasesRoot tcr            = new TestCasesRoot();
            int           expectedResult = 0;
            long          result         = tcr.CalculatePossibleCombinations();

            Assert.That(result == expectedResult);

            expectedResult = 4;
            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 4, 0, 0, 3)));
            tcr.Conditions.Add(ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 4, 0, 0, 3)));
            result = tcr.CalculatePossibleCombinations();
            Assert.That(result == expectedResult);

            // 2 invalids
            var cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 6, 0, 0, 3));

            cond.EnumValues[5].IsInvalid = true;
            tcr.Conditions.Add(cond);
            expectedResult *= 3;
            result          = tcr.CalculatePossibleCombinations();
            Assert.That(result == expectedResult);

            cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 2, 0, 0, 1));
            tcr.Conditions.Add(cond);
            result = tcr.CalculatePossibleCombinations();
            Assert.That(result == expectedResult);

            cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 1, 0, 0, 0));
            tcr.Conditions.Add(cond);
            result = tcr.CalculatePossibleCombinations();
            Assert.That(result == expectedResult);

            cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 0, 0, 0, 0));
            tcr.Conditions.Add(cond);
            result = tcr.CalculatePossibleCombinations();
            Assert.That(result == expectedResult);

            cond = ConditionObject.Create("name", TestCasesRoot.CreateSampleEnum("name", 2, 0, -1, -1));
            tcr.Conditions.Add(cond);
            expectedResult *= 2;
            result          = tcr.CalculatePossibleCombinations();
            Assert.That(result == expectedResult);
        }
        internal void CollectValues(TestCasesRoot testCasesRoot)
        {
            TestCaseContainers = new List <TestCaseContainer>();
            foreach (TestCase testCase in testCasesRoot.TestCases)
            {
                TestCaseContainer container = new TestCaseContainer();
                container.Name = testCase.Name;

                var selValues = new SelectedValues();
                selValues.Collect(testCase.Conditions);
                container.TestCaseConditionValues = selValues;

                selValues = new SelectedValues();
                selValues.Collect(testCase.Actions);
                container.TestCaseActionValues = selValues;

                TestCaseContainers.Add(container);
            }
        }
Esempio n. 23
0
        public void CreateMissingTestCases(int idx, string fileName, int expectedTestCasesCount)
        {
            string testOutput = Path.Combine(TestSupport.CreatedFilesDirectory, fileName + ".Output.txt");

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

            tcr.Load(source);

            StringBuilder sb = new StringBuilder();

            foreach (TestCase tc in tcr.TestCases)
            {
                DumpTestCase(sb, tc);
                sb.AppendLine();
            }

            tcr.CalculateMissingTestCases();

            sb.AppendLine("After calculation");
            foreach (TestCase tc in tcr.TestCases)
            {
                DumpTestCase(sb, tc);
                sb.AppendLine();
            }
            File.WriteAllText(testOutput, sb.ToString());
            ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", testOutput);

            //Process.Start(info);

            tcr.Save(target);

            var statistics = tcr.CalculateStatistics();

            if (tcr.TestCases.Count > 0)
            {
                Assert.IsTrue(statistics.Coverage >= 99.9);
            }
            Assert.IsTrue(tcr.TestCases.Count == expectedTestCasesCount);

            TestUtils.CheckTestCasesAndConditionsAndActions(tcr);
        }
Esempio n. 24
0
        private void CompareTestCases(TestCasesRoot tcr, int sourceIndex, int targetIndex)
        {
            TestCase sourceTestCase = tcr.TestCases[sourceIndex];
            TestCase targetTestCase = tcr.TestCases[targetIndex];

            Assert.That(sourceTestCase.Description.Equals(targetTestCase.Description));

            Assert.That(sourceTestCase.Conditions.Count == targetTestCase.Conditions.Count);
            for (int idx = 0; idx < sourceTestCase.Conditions.Count; idx++)
            {
                Assert.That(sourceTestCase.Conditions[idx].SelectedItemIndex == targetTestCase.Conditions[idx].SelectedItemIndex);
            }

            Assert.That(sourceTestCase.Actions.Count == targetTestCase.Actions.Count);
            for (int idx = 0; idx < sourceTestCase.Actions.Count; idx++)
            {
                Assert.That(sourceTestCase.Actions[idx].SelectedItemIndex == targetTestCase.Actions[idx].SelectedItemIndex);
            }
        }
        public void PrepareHtmlForClipboard()
        {
            string        resultPath         = Path.Combine(TestSupport.CreatedFilesDirectory, "output.txt");
            string        resultPathHtml     = Path.Combine(TestSupport.CreatedFilesDirectory, "html.txt");
            string        resultPathFragment = Path.Combine(TestSupport.CreatedFilesDirectory, "fragment.txt");
            TestCasesRoot tcRoot             = TestCasesRoot.CreateSimpleTable();
            var           templResult        = tcRoot.GenerateFromTemplateString(DecisionTableCreator.Templates.Resources.HtmlTemplate);

            PrepareForClipboard prepare = new PrepareForClipboard();
            string result = prepare.Prepare(templResult.GeneratedContent);

            Assert.That(!templResult.ErrorListener.ErrorReported);

            File.WriteAllText(resultPath, result);
            File.WriteAllText(resultPathHtml, result.Substring(prepare.StartHtml, prepare.EndHtml - prepare.StartHtml));
            File.WriteAllText(resultPathFragment, result.Substring(prepare.StartFragment, prepare.EndFragment - prepare.StartFragment));
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(resultPathHtml)));
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(resultPathFragment)));
            Assert.That(TestSupport.CompareFile(TestSupport.CreatedFilesDirectory, TestSupport.ReferenceFilesDirectory, Path.GetFileName(resultPath)));
        }
Esempio n. 26
0
        public void CompareTestCases2Test(int selected11, int selected12, int selected13, int selected21, int selected22, int selected23, bool unique1, bool unique2, int expectedCoveredCount)
        {
            TestCasesRoot tcr   = new TestCasesRoot();
            var           enum1 = TestCasesRoot.CreateSampleEnum("enum1", 6, 0, 0, 5);
            var           enum2 = TestCasesRoot.CreateSampleEnum("enum2", 6, 0, 0, 5);
            var           enum3 = TestCasesRoot.CreateSampleEnum("enum3", 6, 0, 0, 5);

            tcr.Conditions.Add(ConditionObject.Create("enum1", enum1));
            tcr.Conditions.Add(ConditionObject.Create("enum2", enum2));
            tcr.Conditions.Add(ConditionObject.Create("enum3", enum3));
            List <ValueObject> conditions1 = new List <ValueObject>();

            conditions1.Add(new ValueObject(enum1, selected11));
            conditions1.Add(new ValueObject(enum2, selected12));
            conditions1.Add(new ValueObject(enum3, selected13));
            List <ValueObject> conditions2 = new List <ValueObject>();

            conditions2.Add(new ValueObject(enum1, selected21));
            conditions2.Add(new ValueObject(enum2, selected22));
            conditions2.Add(new ValueObject(enum3, selected23));

            TestCase tc1 = tcr.InsertTestCase();

            tc1.SetValues(tcr, conditions1, new List <ValueObject>());
            TestCase tc2 = tcr.InsertTestCase();

            tc2.SetValues(tcr, conditions2, new List <ValueObject>());
            Trace.WriteLine(tc1);
            Trace.WriteLine(tc2);
            bool isEqual = tc1.TestSettingIsEqual(tc2);

            Assert.That(TestCase.UpdateUniqueness(tc1, tc2) == (unique1 && unique2));
            long count = tcr.CalculateNumberOfUniqueCoveredTestCases();

            Assert.That(tc1.TestCaseIsUnique == unique1);
            Assert.That(tc2.TestCaseIsUnique == unique2);
            Assert.That(count == expectedCoveredCount);
        }
Esempio n. 27
0
        public void ClearAllFieldsOnNewTest()
        {
            TestCasesRoot testCasesRoot = new TestCasesRoot();

            testCasesRoot.CreateSampleProject();

            // create and save the sample project
            string savePath = Path.Combine(TestSupport.CreatedFilesDirectory, "SampleProject.dtc");

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

            testCasesRoot.New();
            savePath = Path.Combine(TestSupport.CreatedFilesDirectory, "EmptyProject.dtc");
            testCasesRoot.Save(savePath);
            //ProcessStartInfo info = new ProcessStartInfo(@"C:\Program Files (x86)\Notepad++\notepad++.exe", savePath);
            //Process.Start(info);

            Assert.That(testCasesRoot.Description == String.Empty);
            Assert.That(testCasesRoot.Actions != null && testCasesRoot.Actions.Count == 0);
            Assert.That(testCasesRoot.Conditions != null && testCasesRoot.Conditions.Count == 0);
            Assert.That(testCasesRoot.TestCases != null && testCasesRoot.TestCases.Count == 0);
        }
Esempio n. 28
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));
        }
Esempio n. 29
0
        public void CalculateUniqueTestCases(int id, int[] values, int expectedResult)
        {
            TestCasesRoot tcr = new TestCasesRoot();
            List <List <ValueObject> > listOfValueLists = new List <List <ValueObject> >();

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

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

            //0
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2),
            });
            //2
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 2), new ValueObject(enum2, 3), new ValueObject(enum3, 3),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 2), new ValueObject(enum2, 3), new ValueObject(enum3, 3),
            });
            //4
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 3),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 3),
            });
            //6
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 2), new ValueObject(enum3, 3),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 2), new ValueObject(enum3, 3),
            });
            //8
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 4),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 3), new ValueObject(enum2, 3), new ValueObject(enum3, 4),
            });
            //10
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 5),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 5),
            });
            //12
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 3),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 3),
            });
            //14 not valid for unique count
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 0),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 2), new ValueObject(enum2, 2), new ValueObject(enum3, 0),
            });
            //16
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2),
            });
            //18
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2),
            });
            listOfValueLists.Add(new List <ValueObject>()
            {
                new ValueObject(enum1, 1), new ValueObject(enum2, 2), new ValueObject(enum3, 2),
            });

            List <TestCase> testCases = new List <TestCase>();

            for (int idx = 0; idx < values.Length; idx++)
            {
                TestCase tc = tcr.InsertTestCase();
                tc.SetValues(tcr, listOfValueLists[values[idx]], new List <ValueObject>());
                //TestCase tc = new TestCase(String.Format("tc {0:d2} {1:d2}", idx, values[idx]), listOfValueLists[values[idx]], new List<ValueObject>());
                //testCases.Add(tc);
                //Trace.WriteLine(tc);
            }
            long result = tcr.CalculateNumberOfUniqueCoveredTestCases();

            Assert.That(result == expectedResult);
        }
 internal void DeleteTestCase(TestCase deletedTestCase, TestCasesRoot testCasesRoot)
 {
     TestCaseContainers.Remove(GetContainerByName(deletedTestCase.Name));
 }