示例#1
0
        private void MultipleInputData(StreamWriter sw, TestStepForTCC step, int j)
        {
            String[] stepMethodEntries = step.Input.Split(',');
            String[] stepMethodOutputs = step.Output.Split(',');

            //for (int j = 0; j < stepMethodEntries.Count(); j++)
            {
                String[] singleEntryParams      = stepMethodEntries[j].Split(';');
                String   stepMethodSingleOutput = stepMethodOutputs[j];
                String   lineToWrite            = "\t\t" + "assertEquals(" + step.Receiver.ToLower() + "." + step.Method + "(";

                foreach (String singleEntryParam in singleEntryParams)
                {
                    String singleEntryParamAux = singleEntryParam;

                    if (singleEntryParam.Contains('{'))
                    {
                        singleEntryParamAux = singleEntryParamAux.Substring(1);
                    }
                    if (singleEntryParam.Contains('}'))
                    {
                        singleEntryParamAux = singleEntryParamAux.Substring(0, singleEntryParamAux.Length - 1);
                    }
                    lineToWrite += singleEntryParamAux + ",";
                }

                if (stepMethodSingleOutput.Contains('{'))
                {
                    stepMethodSingleOutput = stepMethodSingleOutput.Substring(1);
                }
                if (stepMethodSingleOutput.Contains('}'))
                {
                    stepMethodSingleOutput = stepMethodSingleOutput.Substring(0, stepMethodSingleOutput.Length - 1);
                }

                lineToWrite  = lineToWrite.Substring(0, lineToWrite.Length - 1);
                lineToWrite += ")," + stepMethodSingleOutput + ");";
                sw.WriteLine(lineToWrite);
            }
        }
示例#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);
        }