예제 #1
0
        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();
        }
예제 #2
0
        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)}");
        }
예제 #3
0
 public void ExtractJavaTestClass(string traceDirectory, JavaTestClass javaTestClass)
 {
     foreach (var method in javaTestClass.Methods)
     {
         var report = GetReport(traceDirectory, javaTestClass, method);
         AddLineCoveragesFromReport(report, method);
     }
 }
예제 #4
0
        public void AddTestMethodsToTestClass(XmlDocument document, JavaTestClass testTestClass)
        {
            var nodeList = SelectTestMethodList(document);

            foreach (XmlNode node in nodeList)
            {
                testTestClass.AddMethod(GetJavaMethod(node));
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
        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}");
        }
예제 #7
0
        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();
        }
예제 #8
0
        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}",
                      };
            }
        }
예제 #9
0
        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}");
        }
예제 #10
0
        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}");
        }
예제 #11
0
 private static string GetNameFromJavaMethod(JavaTestClass javaTestClass, JavaTestMethod javaTestMethod)
 => $"{GetNameFromJavaClass(javaTestClass)}#{javaTestMethod}";
예제 #12
0
 private static string GetNameFromJavaClass(JavaTestClass javaTestClass)
 => $"{javaTestClass.Package}.{javaTestClass.Name}";
예제 #13
0
        public Report GetReport(string traceDirectory, JavaTestClass javaTestClass, JavaTestMethod testMethod)
        {
            var fileUri = Path.Combine(traceDirectory, $"{javaTestClass.Name}-{testMethod.Name}.xml");

            return(GetReport(fileUri));
        }
예제 #14
0
        public void MapTestMethodsImplementation(string reflectionDirectory, JavaTestClass testTestClass)
        {
            var document = GetXmlDocument(reflectionDirectory, testTestClass);

            AddTestMethodsToTestClass(document, testTestClass);
        }
예제 #15
0
        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();
        }
예제 #16
0
 private static string GetCommandOptions(string workingDirectory, JavaTestClass javaTestClass, string reflectionDirectory)
 => $"{ClassPathOption} {ClassPath} {SubCommand} {workingDirectory}{javaTestClass.PackageDirectory}\\ {javaTestClass.Package}.{javaTestClass.Name} {reflectionDirectory}";