private void startRunningSimpleProjectTests(TmcProjectInfo projectInfo) { FileObject testDir = findTestDir(projectInfo); if (testDir == null) { dialogDisplayer.displayError("No test directory in project"); return; } List<TestMethod> tests = findProjectTests(projectInfo, testDir); startRunningSimpleProjectTests(projectInfo, testDir, tests); }
public RunTestsLocallyAction() { this.settings = TmcSettings.getDefault(); this.courseDb = CourseDb.getInstance(); this.projectMediator = ProjectMediator.getInstance(); this.resultDisplayer = TestResultDisplayer.getInstance(); this.dialogDisplayer = ConvenientDialogDisplayer.getDefault(); this.submitAction = new SubmitExerciseAction(); this.eventBus = TmcEventBus.getDefault(); putValue("noIconInMenu", Boolean.TRUE); }
private void handleTestResults(final TmcProjectInfo projectInfo, File resultsFile) { List<TestCaseResult> results; try { String resultJson = FileUtils.readFileToString(resultsFile, "UTF-8"); results = parseTestResults(resultJson); } catch (Exception ex) { log.log(Level.WARNING, "Failed to read test results: {0}", ex.getStackTrace()); dialogDisplayer.displayError("Failed to read test results", ex); return; } boolean canSubmit = submitAction.enable(projectInfo.getProject()); resultDisplayer.showLocalRunResult( results, canSubmit, new Runnable() { @Override public void run() { submitAction.performAction(projectInfo.getProject()); } }); }
private void startRunningSimpleProjectTests( final TmcProjectInfo projectInfo, FileObject testDir, List<TestMethod> testMethods) { File tempFile; try { tempFile = File.createTempFile("tmc_test_results", ".txt"); } catch (IOException ex) { dialogDisplayer.displayError("Failed to create temporary file for test results.", ex); return; } try { ArrayList<String> args = new ArrayList<String>(); args.add("-Dtmc.test_class_dir=" + FileUtil.toFile(testDir).getAbsolutePath()); args.add("-Dtmc.results_file=" + tempFile.getAbsolutePath()); args.add("-D" + ERROR_MSG_LOCALE_SETTING + "=" + settings.getErrorMsgLocale().toString()); if (endorsedLibsExist(projectInfo)) { args.add("-Djava.endorsed.dirs=" + endorsedLibsPath(projectInfo)); } Integer memoryLimit = getMemoryLimit(projectInfo.getProject()); if (memoryLimit != null) { args.add("-Xmx" + memoryLimit + "M"); } args.add("fi.helsinki.cs.tmc.testrunner.Main"); for (int i = 0; i < testMethods.size(); ++i) { args.add(testMethods.get(i).toString()); } InputOutput inOut = getIoTab(); final File tempFileAsFinal = tempFile; ClassPath classPath = getTestClassPath(projectInfo, testDir); runJavaProcessInProject( projectInfo, classPath, "Running tests", args, inOut, new BgTaskListener<ProcessResult>() { @Override public void bgTaskReady(ProcessResult result) { log.info("Test run standard output:"); log.info(result.output); log.info("Test run error output:"); log.info(result.errorOutput); if (result.statusCode != 0) { log.log(Level.INFO, "Failed to run tests. Status code: {0}", result.statusCode); dialogDisplayer.displayError("Failed to run tests.\n" + result.errorOutput); tempFileAsFinal.delete(); return; } try { handleTestResults(projectInfo, tempFileAsFinal); } finally { tempFileAsFinal.delete(); } } @Override public void bgTaskCancelled() { tempFileAsFinal.delete(); } @Override public void bgTaskFailed(Throwable ex) { tempFileAsFinal.delete(); dialogDisplayer.displayError("Failed to run tests", ex); } }); } catch (Exception ex) { tempFile.delete(); dialogDisplayer.displayError("Failed to run tests", ex); } }