private void btnExecuteTest_Click(object sender, EventArgs e) { ofdFile.InitialDirectory = _testSutieFilesDir; if (ofdFile.ShowDialog() == DialogResult.OK) { var testSuite = GetTestSuiteInfoFromTestSuiteFile(ofdFile.FileName); var testSummery = testSuite.TestSummery; var assertions = testSuite.TestCases.SelectMany(c => c.Assertions).ToList(); _function = AbstractFunction.CreateInstance(testSuite.FunctionName); GenerateUnitTestFile(testSuite); foreach (var assertion in assertions) { assertion.ActualOutput = _function.OriginalFunction(assertion.InputValues.ToArray()); assertion.Result = assertion.ActualOutput == assertion.ExpectedOutput ? "Passed" : "Failed"; } testSummery.Executed = assertions.Count; testSummery.Passed = assertions.Count(a => a.Result == "Passed"); testSummery.Failed = assertions.Count(a => a.Result == "Failed"); GenerateTestSuiteFile(testSuite); } }
private void LoadParameters() { _gaParameters.ChromosomeQuantity = Convert.ToInt32(txtChromosomeQuantity.Text); _gaParameters.ChromosomeLengthForOneSubValue = Convert.ToInt32(txtChromosomeLength.Text); _gaParameters.RetainRate = Convert.ToDouble(txtRetainRate.Text) / 100; _gaParameters.MutationRate = Convert.ToDouble(txtMutationRate.Text) / 100; _gaParameters.SelectionRate = Convert.ToDouble(txtSelectionRate.Text) / 100; _gaParameters.GenerationQuantity = Convert.ToInt32(txtGenerationQuantity.Text); _gaParameters.SelectionType = (Population.SelectionType)Enum.Parse(typeof(Population.SelectionType), cmbStrategy.SelectedValue.ToString()); //读取文本框中所有的期望路径 _targetPaths = GetTargetPaths(); //被测函数 _function = AbstractFunction.CreateInstance(cmbFunction.SelectedValue.ToString()); //被测函数适应度计算方法 _function.FitnessCaculationType = (AbstractFunction.FitnessType)Enum.Parse( typeof(AbstractFunction.FitnessType), cmbFitnessCaculationType.SelectedValue.ToString()); //被测函数参数列表(_paras 中的项目由 AddFunctionPara() 或 LoadSettings() 添加) _paras = GetParas(); _function.Paras = _paras; //设定被测函数用于匹配的路径为第一条路径 _function.TargetPath = _targetPaths[0]; }
private void btnGA_Click(object sender, EventArgs e) { //路径覆盖测试数据集 var gaAssertions = new List <AssertionInfo>(); //边界值测试数据集 var bounaryTestAssertions = new List <AssertionInfo>(); //加载参数 LoadParameters(); txtResult.Clear(); //通过遗传算法得到路径覆盖测试数据 gaAssertions.AddRange(Task.Run(() => GaTestDataGenerator.GetAssertions(_gaParameters, _function, _targetPaths)).Result); //得到边界值测试数据 bounaryTestAssertions.AddRange(Task.Run(() => BoundaryTestDataGenerator.GetAssertions(_function)).Result); var testSuite = new TestSuiteInfo { Name = $"针对{cmbFunction.Text}函数的测试套件", Target = $"{AbstractFunction.CreateInstance(cmbFunction.SelectedValue.ToString())}" }; testSuite.TestCases.Add(new TestCaseInfo { Name = "路径覆盖测试", Assertions = gaAssertions }); testSuite.TestCases.Add(new TestCaseInfo { Name = "边界值测试", Assertions = bounaryTestAssertions }); GenerateTestSuiteFile(testSuite); // ShowTestData(gaAssertions.Union(bounaryTestAssertions).ToList()); // ShowAssertions(gaAssertions); //将 galog 显示到文本框中 const string logPath = @"c:\#GA_DEMO\galog.txt"; txtResult.AppendText(File.ReadAllText(logPath)); //滚动到光标处 txtResult.ScrollToCaret(); }