@Override public Long getDuration() { TestResultMessage message = getResultMessage(); if (message != null) { return (message.getEndMillis() - message.getStartMillis()); } else { // TODO cache? long duration = 0; for (TestProxy testProxy : getChildren()) { final Long d = testProxy.getDuration(); duration += (d == null ? 0 : d.longValue()); } return duration; } }
private static List<Printable> getPrintables(final TestResultMessage result) { String s = trimStackTrace(result.getStackTrace()); List<Printable> printables = new ArrayList<Printable>(); //figure out if we have a diff we need to hyperlink if (appendDiffChuncks(result, s, printables, COMPARISION_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_SET_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_NOT_SAME_BUT_WAS_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_FOUND_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_HAMCREST_PATTERN)) { return printables; } printables.add(new Chunk(s, ConsoleViewContentType.ERROR_OUTPUT)); return printables; }
private static boolean appendDiffChuncks(final TestResultMessage result, String s, List<Printable> printables, final Pattern pattern) { final Matcher matcher = pattern.matcher(s); if (matcher.matches()) { printables.add(new Chunk(matcher.group(1), ConsoleViewContentType.ERROR_OUTPUT)); //we have an assert with expected/actual, so we parse it out and create a diff hyperlink DiffHyperlink link = new DiffHyperlink(matcher.group(2), matcher.group(3), null) { protected String getTitle() { //TODO should do some more farting about to find the equality assertion that failed and show that as title return result.getTestClass() + '#' + result.getMethod() + "() failed"; } }; //same as junit diff view printables.add(link); printables.add(new Chunk(trimStackTrace(s.substring(matcher.end(3) + 1)), ConsoleViewContentType.ERROR_OUTPUT)); return true; } return false; }
public void addTestResult(TestResultMessage result) { if (testNGResults != null) { int exceptionMark = myExceptionalMark == -1 ? 0 : myExceptionalMark; if (currentTest != null) { final String stackTrace = result.getStackTrace(); if (stackTrace != null && stackTrace.length() > 10) { exceptionMark = currentTest.getCurrentSize(); //trim useless crud from stacktrace currentTest.appendStacktrace(result); } final TestProxy failedToStart = testNGResults.getFailedToStart(); if (failedToStart != null) { currentTest.addChild(failedToStart); } } testNGResults.addTestResult(result, exceptionMark); myExceptionalMark = -1; } }
private TestProxy getPackageClassNodeFor(final TestResultMessage result) { TestProxy owner = treeBuilder.getRoot(); final String packageName1 = StringUtil.getPackageName(result.getTestClass()); String packageName = packageName1.length() == 0 ? NO_PACKAGE : packageName1; owner = getChildNodeNamed(owner, packageName); if (owner.getPsiElement() == null) { owner.setPsiElement(JavaPsiFacade.getInstance(project).findPackage(packageName)); } owner = getChildNodeNamed(owner, StringUtil.getShortName(result.getTestClass())); //look up the psiclass now if (owner.getPsiElement() == null) { final TestProxy finalOwner = owner; ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { finalOwner.setPsiElement(ClassUtil.findPsiClass(PsiManager.getInstance(project), result.getTestClass())); } }); } return owner; }
public static boolean isVersionIncompatible(Project project, GlobalSearchScope scope) { final String protocolClassMessageClass = TestResultMessage.class.getName(); final PsiClass psiProtocolClass = JavaPsiFacade.getInstance(project).findClass(protocolClassMessageClass, scope); if (psiProtocolClass != null) { final String instanceFieldName = "m_instanceName"; try { final boolean userHasNewJar = psiProtocolClass.findFieldByName(instanceFieldName, false) != null; boolean ideaHasNewJar = true; final Class aClass = Class.forName(protocolClassMessageClass); try { aClass.getDeclaredField(instanceFieldName); } catch (NoSuchFieldException e) { ideaHasNewJar = false; } return userHasNewJar != ideaHasNewJar; } catch (Exception ignore) { } } return false; }
private static List<Printable> getPrintables(final TestResultMessage result) { String s = trimStackTrace(result.getStackTrace()); List<Printable> printables = new ArrayList<Printable>(); //figure out if we have a diff we need to hyperlink if (appendDiffChuncks(result, s, printables, COMPARISION_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_WAS_SET_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_NOT_SAME_BUT_WAS_PATTERN)) { return printables; } if (appendDiffChuncks(result, s, printables, EXPECTED_BUT_FOUND_PATTERN)) { return printables; } printables.add(new Chunk(s, ConsoleViewContentType.ERROR_OUTPUT)); return printables; }
public String valueOf(final TestResultMessage result) { switch (result.getResult()) { case MessageHelper.PASSED_TEST: return "Pass"; case MessageHelper.FAILED_TEST: return "Fail"; case MessageHelper.SKIPPED_TEST: return "Skipped"; case MessageHelper.FAILED_ON_PERCENTAGE_TEST: return "Failed On %"; default: return "Unknown result " + result.getResult(); } }
public Comparator<TestResultMessage> getComparator() { return new Comparator<TestResultMessage>() { public int compare(final TestResultMessage o1, final TestResultMessage o2) { return o1.getResult() - o2.getResult(); } }; }
public Comparator<TestResultMessage> getComparator() { return new Comparator<TestResultMessage>() { public int compare(final TestResultMessage o1, final TestResultMessage o2) { return o1.getMethod().compareToIgnoreCase(o2.getMethod()); } }; }
public Comparator<TestResultMessage> getComparator() { return new Comparator<TestResultMessage>() { public int compare(final TestResultMessage o1, final TestResultMessage o2) { return o1.getTestClass().compareToIgnoreCase(o2.getTestClass()); } }; }
public String valueOf(final TestResultMessage result) { long time = getDuration(result); if (time == 0) { return "0.0 s"; } return NumberFormat.getInstance().format((double)time/1000.0) + " s"; }
public Comparator<TestResultMessage> getComparator() { return new Comparator<TestResultMessage>() { public int compare(final TestResultMessage o1, final TestResultMessage o2) { return (int)(getDuration(o1) - getDuration(o2)); } }; }
public void setResultMessage(final TestResultMessage resultMessage) { //if we have a result, then our parent is a class, so we can look up our method //this is a bit fragile as it assumes parent is set first and correctly ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { PsiClass psiClass = (PsiClass)getParent().getPsiElement(); if (psiClass != null) { PsiMethod[] methods = psiClass.getAllMethods(); for (PsiMethod method : methods) { if (method.getName().equals(resultMessage.getMethod())) { setPsiElement(method); break; } } } } }); TestProxy current = this; while (current != null) { current.inProgress = resultMessage.getResult() == MessageHelper.TEST_STARTED; current = current.getParent(); } if (this.resultMessage == null || this.resultMessage.getResult() == MessageHelper.TEST_STARTED) { this.resultMessage = resultMessage; final PsiElement psiElement = getPsiElement(); this.name = toDisplayText(resultMessage, psiElement != null ? psiElement.getProject() : null); } }
public static String toDisplayText(TestResultMessage message, Project project) { String name = message.getName(); if (project != null && Comparing.strEqual(name, project.getName())) { name = message.getMethod(); } final String mainNamePart = name; final String[] parameters = message.getParameters(); if (parameters != null && parameters.length > 0) { final String[] parameterTypes = message.getParameterTypes(); name += " ("; for(int i= 0; i < parameters.length; i++) { if(i > 0) { name += ", "; } if(CommonClassNames.JAVA_LANG_STRING.equals(parameterTypes[i]) && !("null".equals(parameters[i]) || "\"\"".equals(parameters[i]))) { name += "\"" + parameters[i] + "\""; } else { name += parameters[i]; } } name += ")"; } final String testDescription = message.getTestDescription(); if (testDescription != null && !Comparing.strEqual(testDescription, mainNamePart)) { name += " [" + testDescription + "]"; } return name; }
public TestNGResults(final JComponent component, final TestNGConfiguration configuration, final TestNGConsoleView console) { super(component, console.getConsole().createConsoleActions(), console.getProperties(), TESTNG_SPLITTER_PROPERTY, 0.5f); this.configuration = configuration; this.project = configuration.getProject(); model = new TestNGResultsTableModel(project); resultsTable = new TableView(model); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { final Object result = resultsTable.getSelectedObject(); if (result instanceof TestResultMessage) { final String testClass = ((TestResultMessage)result).getTestClass(); final PsiClass psiClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), testClass); if (psiClass != null) { final String method = ((TestResultMessage)result).getMethod(); if (method != null) { final PsiMethod[] psiMethods = psiClass.findMethodsByName(method, false); if (psiMethods.length > 0) { psiMethods[0].navigate(true); } } psiClass.navigate(true); return true; } } return false; } }.installOn(resultsTable); rootNode = new TreeRootNode(); console.getUnboundOutput().addChild(rootNode); }
public TestProxy testStarted(TestResultMessage result, boolean registerDups) { TestProxy classNode = getPackageClassNodeFor(result); TestProxy proxy = new TestProxy(); proxy.setParent(classNode); proxy.setResultMessage(result); synchronized (started) { if (registerDups) { List<TestProxy> dups = started.get(result); if (dups == null) { dups = new ArrayList<TestProxy>(); started.put(result, dups); } dups.add(proxy); } } final String testMethodDescriptor = result.getTestClass() + TestProxy.toDisplayText(result, project); if (startedMethods.contains(testMethodDescriptor)) { total++; } else { startedMethods.add(testMethodDescriptor); } animator.setCurrentTestCase(proxy); treeBuilder.addItem(classNode, proxy); //treeBuilder.repaintWithParents(proxy); count++; if (count > total) total = count; if (myLastSelected == proxy) { myLastSelected = null; } if (myLastSelected == null && TestConsoleProperties.TRACK_RUNNING_TEST.value(myProperties)) { selectTest(proxy); } return proxy; }
@Override public void startElement (String uri, String localName, String qName, Attributes attributes) { p("Start " + qName); if (TAG_SUITE.equals(qName)) { m_suiteListener.onInitialization(new GenericMessage()); m_suiteMethodCount = 0; m_currentSuite = new SuiteMessage(attributes.getValue(ATTR_NAME), true /* start */, m_suiteMethodCount); m_suiteListener.onStart(m_currentSuite); } else if (TAG_TEST.equals(qName)) { m_passed = m_failed = m_skipped = 0; m_currentTest = new TestMessage(true /* start */, m_currentSuite.getSuiteName(), attributes.getValue(ATTR_NAME), m_testMethodCount, m_passed, m_failed, m_skipped, 0); m_testListener.onStart(m_currentTest); } else if (TAG_CLASS.equals(qName)) { m_className = attributes.getValue(ATTR_NAME); } else if (TAG_TEST_METHOD.equals(qName)) { Integer status = XMLReporterConfig.getStatus(attributes.getValue(ATTR_STATUS)); m_currentTestResult = new TestResultMessage(status, m_currentSuite.getSuiteName(), m_currentTest.getTestName(), m_className, attributes.getValue(ATTR_NAME), attributes.getValue(ATTR_DESC), attributes.getValue(ATTR_DESC), new String[0], /* no parameters, filled later */ 0, Long.parseLong(attributes.getValue(ATTR_DURATION_MS)), "" /* stack trace, filled later */, m_invocationCount, m_currentInvocationCount); m_suiteMethodCount++; m_testMethodCount++; if (status == ITestResult.SUCCESS) m_passed++; else if (status == ITestResult.FAILURE) m_failed++; else if (status == ITestResult.SKIP) m_skipped++; } else if (TAG_PARAMS.equals(qName)) { m_params = Lists.newArrayList(); } }
public TestNGResults(final JComponent component, final TestNGConfiguration configuration, final TestNGConsoleView console, final ExecutionEnvironment environment) { super(component, console.getConsole().createConsoleActions(), console.getProperties(), environment, TESTNG_SPLITTER_PROPERTY, 0.5f); this.project = configuration.getProject(); model = new TestNGResultsTableModel(project); resultsTable = new TableView(model); new DoubleClickListener() { @Override protected boolean onDoubleClick(MouseEvent e) { final Object result = resultsTable.getSelectedObject(); if (result instanceof TestResultMessage) { final String testClass = ((TestResultMessage)result).getTestClass(); final PsiClass psiClass = ClassUtil.findPsiClass(PsiManager.getInstance(project), testClass); if (psiClass != null) { final String method = ((TestResultMessage)result).getMethod(); if (method != null) { final PsiMethod[] psiMethods = psiClass.findMethodsByName(method, false); if (psiMethods.length > 0) { psiMethods[0].navigate(true); } } psiClass.navigate(true); return true; } } return false; } }.installOn(resultsTable); rootNode = new TreeRootNode(); console.getUnboundOutput().addChild(rootNode); }
public TestNGResultsTableModel(Project project) { super(new StatusColumnInfo(), new TestNameColumnInfo(project), new TestClassNameColumnInfo(project), new DurationColumnInfo()); testResults = new ArrayList<TestResultMessage>(); }
public void addTestResult(TestResultMessage result) { testResults.add(result); setItems(testResults); }
private static long getDuration(final TestResultMessage result) { return result.getEndMillis() - result.getStartMillis(); }
public String valueOf(final TestResultMessage result) { final String displayString = TestProxy.toDisplayText(result, project); final String description = result.getTestDescription(); if (description != null && description.startsWith(displayString)) return description; return displayString; }
public String valueOf(final TestResultMessage result) { final String description = result.getTestClass(); if (description != null) return description; return TestProxy.toDisplayText(result, project); }
public TestResultMessage getResultMessage() { return resultMessage; }
public void testStarted(TestResultMessage result) { if (testNGResults != null) { currentTest = testNGResults.testStarted(result); } }