public void CompareToStudentMethod(InstructorTestDto instructorTestDto, JavaTestMethod instructorTestMethod, JavaTestMethod studentTestMethod) { if (Covered(instructorTestMethod, studentTestMethod)) { TestStatusEnum status; switch (instructorTestDto.StudentTests.Count) { case 0: status = TestStatusEnum.Uncovered; break; case 1: status = TestStatusEnum.Covered; break; default: { status = TestStatusEnum.Redundant; break; } } instructorTestDto.StudentTests.Add(new StudentTestDto { Name = studentTestMethod.Name, Passed = studentTestMethod.Passed, TestStatus = status }); } }
public InstructorTestDto GetInstructorTestDto(JavaTestMethod referenceTestMethod, List <JavaTestClass> studentTests) { var instructorTestDto = new InstructorTestDto { Name = referenceTestMethod.Name, EquivalenceClass = referenceTestMethod.EquivalenceClass, Concepts = referenceTestMethod.LearningConcepts, Passed = referenceTestMethod.Passed, }; foreach (var studentTestClass in studentTests) { foreach (var studentMethod in studentTestClass.Methods) { if (studentMethod.LearningConcepts == null) { CompareToStudentMethod(instructorTestDto, referenceTestMethod, studentMethod); } } } MarkInstructorDto(instructorTestDto); return(instructorTestDto); }
public void RunTestMethod(JavaTestClass javaTestClass, JavaTestMethod javaTestMethod, string originalCodeDirectory, string traceDirectory, string referenceCode = null) { var packageClassAndMethod = $"{javaTestClass.Package}.{javaTestClass.Name}#{javaTestMethod.Name}"; var commandOptions = GetCommandOptions(packageClassAndMethod, originalCodeDirectory, javaTestClass.ClassPath, javaTestClass.Name, javaTestMethod.Name, traceDirectory, referenceCode); var process = new EngineProcess(Command, commandOptions, originalCodeDirectory); try { var exitCode = process.Run(); javaTestMethod.Passed = exitCode == 0; } catch (Exception e) { var exception = new EngineExceptionDto() { Report = JavaEngineReportExceptionFactory .GenerateReportForJunitTestRunnerTestMethodProcess(process, e, javaTestClass, javaTestMethod) }; process.Stop(); throw exception; } process.Stop(); }
public static string GenerateReportForAnalysisLineCoverage(JavaTestMethod reference, JavaTestMethod student) { return("Failure to Trace Analysis.\n" + "Line number counts between reference and student are not the same.\n" + $"Method Name: {reference.Name}." + $"Reference Line Coverage Count: {reference.LineCoverages.Count}." + $"Student Line Coverage Count: {student.LineCoverages.Count}."); }
public static string GenerateReportForTraceJavaMethod(EngineProcess p, Exception e, JavaTestClass javaTestClass, JavaTestMethod javaTestMethod) { var name = GetNameFromJavaMethod(javaTestClass, javaTestMethod); var traceError = GetErrorFromProcess(p); return("Failure to run trace on java testMethod.\n" + $"Name of Java Method: {name}\n" + $"{GetMessageFromException(e)}\n" + $"Trace Error:\n{traceError}"); }
public void AddLineCoveragesFromReport(Report report, JavaTestMethod testMethod) { foreach (var sourceFile in GetTestFiles(report)) { foreach (var line in sourceFile.Lines) { testMethod.AddLineCoverage(new LineCoverage { LineNumber = line.LineNumber, CoveredBranches = line.CoveredBranches, MissedBranches = line.MissedBranches, CoveredInstructions = line.CoveredInstructions, MissedInstructions = line.MissingInstructions }); } } }
private static bool Covered(JavaTestMethod referenceTestMethod, JavaTestMethod studentTestMethod) { if (referenceTestMethod.LineCoverages.Count != studentTestMethod.LineCoverages.Count) { throw new EngineExceptionDto() { Report = JavaEngineReportExceptionFactory.GenerateReportForAnalysisLineCoverage(referenceTestMethod, studentTestMethod) } } ; return(!referenceTestMethod.LineCoverages.Where((r, i) => !(r.CoveredInstructions > 0 ? studentTestMethod.LineCoverages[i].CoveredInstructions > 0 : studentTestMethod.LineCoverages[i].CoveredInstructions == 0)).Any()); //return !referenceTestMethod.LineCoverages.Where((t, i) => t.CoveredBranches > studentTestMethod.LineCoverages[i].CoveredBranches // || t.CoveredInstructions > studentTestMethod.LineCoverages[i].CoveredInstructions // || t.MissedBranches < studentTestMethod.LineCoverages[i].MissedBranches // || t.MissedInstructions < studentTestMethod.LineCoverages[i].MissedInstructions).Any(); } }
public void TraceJavaMethod(JavaTestClass javaTestClass, JavaTestMethod testMethod, string workingDirectory) { var commandOptions = GetCommandOptions(javaTestClass.Name, testMethod.Name, javaTestClass.ClassPath); var process = new EngineProcess(Command, commandOptions, workingDirectory); try { process.Run(); } catch (Exception e) { var exception = new EngineExceptionDto() { Report = JavaEngineReportExceptionFactory .GenerateReportForTraceJavaMethod(process, e, javaTestClass, testMethod) }; process.Stop(); throw exception; } process.Stop(); }
public static string GenerateReportForJunitTestRunnerTestMethodProcess(EngineProcess p, Exception e, JavaTestClass javaTestClass, JavaTestMethod javaTestMethod) { var name = GetNameFromJavaMethod(javaTestClass, javaTestMethod); var junitTestError = GetErrorFromProcess(p); return("Failure to junit test runner for test testMethod.\n" + $"Name of Java Method: {name}\n" + $"{GetMessageFromException(e)}\n" + $"Junit Test Error:\n{junitTestError}"); }
private static string GetNameFromJavaMethod(JavaTestClass javaTestClass, JavaTestMethod javaTestMethod) => $"{GetNameFromJavaClass(javaTestClass)}#{javaTestMethod}";
public Report GetReport(string traceDirectory, JavaTestClass javaTestClass, JavaTestMethod testMethod) { var fileUri = Path.Combine(traceDirectory, $"{javaTestClass.Name}-{testMethod.Name}.xml"); return(GetReport(fileUri)); }