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 GenerateReportForReflectionMapping(Exception e, JavaTestClass javaTestClass) { var name = GetNameFromJavaClass(javaTestClass); return("Failure to reflex and map test methods.\n" + $"Name of Java Class: {name}\n" + $"{GetMessageFromException(e)}"); }
public void ExtractJavaTestClass(string traceDirectory, JavaTestClass javaTestClass) { foreach (var method in javaTestClass.Methods) { var report = GetReport(traceDirectory, javaTestClass, method); AddLineCoveragesFromReport(report, method); } }
public void AddTestMethodsToTestClass(XmlDocument document, JavaTestClass testTestClass) { var nodeList = SelectTestMethodList(document); foreach (XmlNode node in nodeList) { testTestClass.AddMethod(GetJavaMethod(node)); } }
public XmlDocument GetXmlDocument(string reflectionDirectory, JavaTestClass javaTestClass) { var className = javaTestClass.Name; var xmlFileUri = $"{reflectionDirectory}{className}.xml"; var xmlDocument = new XmlDocument(); xmlDocument.Load(xmlFileUri); return(xmlDocument); }
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}"); }
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 void ValidateStudentJavaTestClasses(List <JavaTestClass> studentJavaTestClasses) { bool failed = false; var failedJavaTestClass = new List <JavaTestClass>(); studentJavaTestClasses.ForEach(x => { var javaClass = new JavaTestClass() { Name = x.Name, Package = x.Package, PackageDirectory = x.PackageDirectory, }; x.Methods.ToList().ForEach(y => { if (!y.Passed) { javaClass.AddMethod(y); failed = true; } }); failedJavaTestClass.Add(javaClass); }); if (failed) { var report = failedJavaTestClass.Where(x => x.Methods.Any()).Select(x => { var methods = $"{x.Package}.{x.Name}:\n{x.Methods.Select(y => y.Name).Join("\n")}"; return(methods); }).Join("\n"); throw new EngineExceptionDto() { Report = "Failed Tests. In Development Mode all your test must passed.\n" + "The following tests failed:\n" + $"{report}", }; } }
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 static string GenerateReportForReflectionProcess(EngineProcess p, Exception e, JavaTestClass javaTestClass) { var reflectionError = GetErrorFromProcess(p); var name = GetNameFromJavaClass(javaTestClass); return($"Failure to reflect.\n" + $"Name of Java Class: {name}\n" + $"{GetMessageFromException(e)}\n" + $"Reflection Error: {reflectionError}"); }
private static string GetNameFromJavaMethod(JavaTestClass javaTestClass, JavaTestMethod javaTestMethod) => $"{GetNameFromJavaClass(javaTestClass)}#{javaTestMethod}";
private static string GetNameFromJavaClass(JavaTestClass javaTestClass) => $"{javaTestClass.Package}.{javaTestClass.Name}";
public Report GetReport(string traceDirectory, JavaTestClass javaTestClass, JavaTestMethod testMethod) { var fileUri = Path.Combine(traceDirectory, $"{javaTestClass.Name}-{testMethod.Name}.xml"); return(GetReport(fileUri)); }
public void MapTestMethodsImplementation(string reflectionDirectory, JavaTestClass testTestClass) { var document = GetXmlDocument(reflectionDirectory, testTestClass); AddTestMethodsToTestClass(document, testTestClass); }
public void GenerateXmlForJavaClass(string codeDirectory, string reflectionDirectory, JavaTestClass javaTestClass) { var process = new EngineProcess(Command, GetCommandOptions(codeDirectory, javaTestClass, reflectionDirectory), codeDirectory); try { process.Run(); } catch (Exception e) { var exception = new EngineExceptionDto() { Report = JavaEngineReportExceptionFactory .GenerateReportForReflectionProcess(process, e, javaTestClass) }; process.Stop(); throw exception; } process.Stop(); }
private static string GetCommandOptions(string workingDirectory, JavaTestClass javaTestClass, string reflectionDirectory) => $"{ClassPathOption} {ClassPath} {SubCommand} {workingDirectory}{javaTestClass.PackageDirectory}\\ {javaTestClass.Package}.{javaTestClass.Name} {reflectionDirectory}";