private void PopulateTestCase(List <String[]> sequence, DirectedGraph dg, TestPlanForTCC testPlan)
        {
            for (int k = 0; k < sequence.Count(); k++)
            {
                Edge        edge            = new Edge();
                List <Edge> edges           = new List <Edge> ();
                String[]    arraySequence   = sequence[k];
                int         maxUseCaseLines = int.MaxValue;
                foreach (String input in arraySequence)
                {
                    edge = GetEdge(input, dg, edge.NodeB);
                    if (edge != null)
                    {
                        edges.Add(edge);

                        foreach (KeyValuePair <String, String> pair in edge.Values)
                        {
                            //int aux = GetUsedFilesLineCount(pair.Value);
                            //if (maxUseCaseLines > aux)
                            {
                                //maxUseCaseLines = aux;
                            }
                        }
                    }
                }

                TestCaseForTCC testCase = null;

                do
                {
                    testCase = FillTestCase(dg, edges, testCase);
                    if (testCase != null)
                    {
                        testPlan.TestCases.Add(testCase);
                    }
                    //currLine++;
                } while (doAgain /*&& (currLine < maxLine)*/);
            }
        }
Exemple #2
0
        private void GenerateJUnitFromTestPlan(List <GeneralUseStructure> listPlanStructure, String path)
        {
            //path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\GeneratedTest.java";

            foreach (GeneralUseStructure planStructure in listPlanStructure)
            {
                TestPlanForTCC testPlan = (TestPlanForTCC)planStructure;
                StreamWriter   sw       = new StreamWriter(path + @"\YourClassTest.java");

                WriteImportsAndConstructor(sw);
                //sw.WriteLine("import org.junit.Before;");

                for (int i = 0; i < testPlan.TestCases.Count; i++)
                {
                    TestCaseForTCC testCase            = testPlan.TestCases[i];
                    int            maxTestCaseQuantity = 0;

                    List <TestStepForTCC> tsWithParameters = (from ts in testCase.TestSteps
                                                              where ts.Input.Contains(',')
                                                              select ts).ToList();

                    foreach (TestStepForTCC ts in tsWithParameters)
                    {
                        int testCaseQuantity = ts.Input.Split(',').Count();

                        if (testCaseQuantity > maxTestCaseQuantity)
                        {
                            maxTestCaseQuantity = testCaseQuantity;
                        }
                    }

                    List <TestStepForTCC> constructors = (from ts in testCase.TestSteps
                                                          where ts.ActionType.Equals("0")
                                                          select ts).ToList();

                    for (int j = 0; j < maxTestCaseQuantity; j++)
                    {
                        WriteTestCaseHeader(sw);

                        foreach (TestStepForTCC constructor in constructors)
                        {
                            String objectName = constructor.Receiver.ToLower();
                            sw.WriteLine("\t\t" + constructor.Receiver + " " + objectName + " = new " + constructor.Receiver + "();");
                        }

                        for (int k = 0; k < testCase.TestSteps.Count; k++)
                        {
                            TestStepForTCC step = testCase.TestSteps[k];
                            if (step.ActionType.Equals("2") || step.ActionType.Equals("0"))
                            {
                                continue;
                            }
                            else
                            {
                                //Método sem parâmetros
                                if (String.IsNullOrEmpty(step.Input))
                                {
                                    sw.WriteLine("\t\t" + step.Receiver.ToLower() + "." + step.Method + "();");
                                }
                                //Testando com apenas um conjunto de parâmetros
                                else if (!step.Input.Contains(','))
                                {
                                    String[] singleEntryParams = step.Input.Split(';');
                                    foreach (String singleEntryParam in singleEntryParams)
                                    {
                                        String singleEntryParamAux = singleEntryParam;

                                        if (singleEntryParam.Contains('{'))
                                        {
                                            singleEntryParamAux = singleEntryParamAux.Substring(1);
                                        }
                                        if (singleEntryParam.Contains('}'))
                                        {
                                            singleEntryParamAux = singleEntryParamAux.Substring(0, singleEntryParam.Length - 1);
                                        }
                                        //TO DO
                                    }
                                }
                                //Testando com diversos conjuntos de parâmetros
                                else
                                {
                                    MultipleInputData(sw, step, j);
                                }
                            }
                        }
                        sw.WriteLine("\t}");
                    }
                }
                sw.WriteLine("}");
                sw.Close();
            }
        }
        private TestCaseForTCC FillTestCase(DirectedGraph dg, List <Edge> edges, TestCaseForTCC testCase)
        {
            TestStepForTCC testStep;
            int            index = 1;

            testCase = new TestCaseForTCC("TestCase" + index);
            //testCase.Title += "_" + TestCaseForTCC.contWorkItemId;
            //testCase.WorkItemId = TestCase.contWorkItemId;
            //testCase.WriteFirstLine = TestCaseTags(dg, testCase);
            //TestCase.contWorkItemId++;
            testStep = new TestStepForTCC();
            //usedFiles = new List<CsvParamFile>();
            foreach (Edge edge in edges)
            {
                readFile = false;
                Boolean isCycle        = false;
                Boolean lastCycleTrans = false;
                if (edge.GetTaggedValue("TDlastCycleTrans") != null)
                {
                    lastCycleTrans = (edge.GetTaggedValue("TDlastCycleTrans").Equals("true") ? true : false);
                }
                if (edge.GetTaggedValue("TDcycleTran") != null)
                {
                    isCycle = true;
                }
                if (lastCycleTrans)
                {
                    //usedFiles = usedFiles.Distinct().ToList();
                    //foreach (CsvParamFile csv in usedFiles)
                    {
                        //csv.NextLine();
                    }
                    //usedFiles.Clear();
                }

                if (isCycle)
                {
                    //testStep = new TestStepForTCC();
                    //testStep.Index = index.ToString();
                    //testStep.Description = GenerateDescription(edge);
                    //testStep.ExpectedResult = GenerateExpectedResult(edge);
                    //testCase.TestSteps.Add(testStep);
                    //index++;
                }
                else
                {
                    testStep            = new TestStepForTCC();
                    testStep.ActionType = edge.GetTaggedValue("ACTIONTYPE");
                    if (!String.IsNullOrEmpty(edge.GetTaggedValue("PARAMS")))
                    {
                        testStep.Input = edge.GetTaggedValue("PARAMS");
                    }
                    else
                    {
                        testStep.Input = "";
                    }
                    //testStep.IsAbstract = Boolean.Parse(edge.GetTaggedValue("METHODABSTRACT"));
                    testStep.Method = edge.GetTaggedValue("METHOD");
                    if (!String.IsNullOrEmpty(edge.GetTaggedValue("EXPECTEDRESULTS")))
                    {
                        testStep.Output = edge.GetTaggedValue("EXPECTEDRESULTS");
                    }
                    else
                    {
                        testStep.Output = "";
                    }
                    testStep.Receiver = edge.NodeB.Name;
                    testStep.Return   = edge.GetTaggedValue("METHODRETURN");
                    testStep.Sender   = edge.NodeA.Name;
                    //testStep.Visibility = edge.GetTaggedValue("METHODVISIBILITY");
                    String aux = edge.GetTaggedValue("METHODPARAMQUANTITY");

                    if (String.IsNullOrEmpty(aux))
                    {
                        aux = "0";
                    }
                    for (int i = 0; i < int.Parse(aux); i++)
                    {
                    }
                    //testStep.Index = index.ToString();
                    //testStep.Description = GenerateDescription(edge);
                    //testStep.ExpectedResult = GenerateExpectedResult(edge);
                    testCase.TestSteps.Add(testStep);
                    index++;
                    if (readFile)
                    {
                        doAgain = true;
                    }
                }
            }
            return(testCase);
        }