summaryrefslogtreecommitdiff
path: root/plugins/testng/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/testng/src')
-rw-r--r--plugins/testng/src/META-INF/plugin.xml3
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/TestNGReferenceContributor.java2
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java26
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java15
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnMethodInspection.java46
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/inspection/TestNGMethodNamingConventionInspection.java105
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/model/TestNGRemoteListener.java4
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java14
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java7
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/ui/TestNGTestTreeView.java2
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java22
-rw-r--r--plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java43
-rw-r--r--plugins/testng/src/inspectionDescriptions/TestNGMethodNamingConvention.html13
13 files changed, 239 insertions, 63 deletions
diff --git a/plugins/testng/src/META-INF/plugin.xml b/plugins/testng/src/META-INF/plugin.xml
index fff400d9f794..5fe0fb55b60f 100644
--- a/plugins/testng/src/META-INF/plugin.xml
+++ b/plugins/testng/src/META-INF/plugin.xml
@@ -46,6 +46,9 @@
<localInspection language="JAVA" shortName="MisorderedAssertEqualsArgumentsTestNG" displayName="Misordered 'assertEquals()' arguments"
groupName="TestNG" enabledByDefault="false" level="WARNING"
implementationClass="com.theoryinpractice.testng.inspection.MisorderedAssertEqualsArgumentsTestNGInspection"/>
+ <localInspection language="JAVA" shortName="TestNGMethodNamingConvention" displayName="TestNG test method naming convention"
+ groupName="TestNG" enabledByDefault="false" level="WARNING"
+ implementationClass="com.theoryinpractice.testng.inspection.TestNGMethodNamingConventionInspection"/>
<intentionAction>
<className>com.theoryinpractice.testng.intention.TestNGOrderEntryFix</className>
diff --git a/plugins/testng/src/com/theoryinpractice/testng/TestNGReferenceContributor.java b/plugins/testng/src/com/theoryinpractice/testng/TestNGReferenceContributor.java
index 0a9acf231499..6e483fb97c3d 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/TestNGReferenceContributor.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/TestNGReferenceContributor.java
@@ -170,7 +170,7 @@ public class TestNGReferenceContributor extends PsiReferenceContributor {
if (cls != null) {
PsiMethod[] methods = cls.findMethodsByName(methodName, true);
for (PsiMethod method : methods) {
- if (TestNGUtil.hasTest(method) || TestNGUtil.hasConfig(method)) {
+ if (TestNGUtil.hasTest(method, false) || TestNGUtil.hasConfig(method)) {
return method;
}
}
diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java
index 413aceebf8d4..2258b16a7a2a 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/SearchingForTestsTask.java
@@ -191,11 +191,22 @@ public class SearchingForTestsTask extends Task.Backgroundable {
private void composeTestSuiteFromClasses() {
Map<String, Collection<String>> map = new HashMap<String, Collection<String>>();
+
+ final boolean findTestMethodsForClass = shouldSearchForTestMethods();
+
for (final Map.Entry<PsiClass, Collection<PsiMethod>> entry : myClasses.entrySet()) {
- Collection<String> methods = new HashSet<String>(entry.getValue().size());
- for (PsiMethod method : entry.getValue()) {
+ final Collection<PsiMethod> depMethods = entry.getValue();
+ Collection<String> methods = new HashSet<String>(depMethods.size());
+ for (PsiMethod method : depMethods) {
methods.add(method.getName());
}
+ if (findTestMethodsForClass && depMethods.isEmpty()) {
+ for (PsiMethod method : entry.getKey().getMethods()) {
+ if (TestNGUtil.hasTest(method)) {
+ methods.add(method.getName());
+ }
+ }
+ }
map.put(ApplicationManager.getApplication().runReadAction(
new Computable<String>() {
@Nullable
@@ -243,6 +254,17 @@ public class SearchingForTestsTask extends Task.Backgroundable {
}
}
+ private boolean shouldSearchForTestMethods() {
+ boolean dependantMethods = false;
+ for (Collection<PsiMethod> methods : myClasses.values()) {
+ if (!methods.isEmpty()) {
+ dependantMethods = true;
+ break;
+ }
+ }
+ return dependantMethods;
+ }
+
private void composeTestSuiteFromXml() throws CantRunException {
final Map<String, String> buildTestParams = buildTestParameters();
try {
diff --git a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java
index 21afb568e912..0c73ae5f5761 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/configuration/TestNGRunnableState.java
@@ -144,19 +144,6 @@ public class TestNGRunnableState extends JavaCommandLineState {
if (mySearchForTestIndicator != null && !mySearchForTestIndicator.isCanceled()) {
task.finish();
}
-
- final Runnable notificationRunnable = new Runnable() {
- public void run() {
- final Project project = config.getProject();
- if (project.isDisposed()) return;
-
- final TestConsoleProperties consoleProperties = console.getProperties();
- if (consoleProperties == null) return;
- final TestNGResults resultsView = console.getResultsView();
- TestsUIUtil.notifyByBalloon(project, myStarted, console.getResultsView().getRoot(), consoleProperties, "in " + resultsView.getTime());
- }
- };
- SwingUtilities.invokeLater(notificationRunnable);
}
@Override
@@ -175,7 +162,7 @@ public class TestNGRunnableState extends JavaCommandLineState {
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
final TestNGResults resultsView = console.getResultsView();
if (resultsView != null) {
- resultsView.finish();
+ resultsView.finish(myStarted);
}
}
diff --git a/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnMethodInspection.java b/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnMethodInspection.java
index b8cf78a83d5d..aeda466432a2 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnMethodInspection.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/inspection/DependsOnMethodInspection.java
@@ -18,14 +18,19 @@ package com.theoryinpractice.testng.inspection;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInspection.*;
import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.util.Condition;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.containers.HashSet;
import com.theoryinpractice.testng.util.TestNGUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -35,7 +40,7 @@ import java.util.regex.Pattern;
public class DependsOnMethodInspection extends BaseJavaLocalInspectionTool
{
private static final Logger LOGGER = Logger.getInstance("TestNG Runner");
- private static final Pattern PATTERN = Pattern.compile("\"([a-zA-Z1-9_\\(\\)]*)\"");
+ private static final Pattern PATTERN = Pattern.compile("\"([a-zA-Z1-9_\\(\\)\\*]*)\"");
@NotNull
@Override
@@ -63,17 +68,13 @@ public class DependsOnMethodInspection extends BaseJavaLocalInspectionTool
@Nullable
public ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
- //LOGGER.info("Looking for dependsOnMethods problems in " + psiClass.getName());
-
- if (!psiClass.getContainingFile().isWritable()) return null;
-
PsiAnnotation[] annotations = TestNGUtil.getTestNGAnnotations(psiClass);
if(annotations.length == 0) return ProblemDescriptor.EMPTY_ARRAY;
List<ProblemDescriptor> problemDescriptors = new ArrayList<ProblemDescriptor>();
for (PsiAnnotation annotation : annotations) {
final PsiAnnotationMemberValue value = annotation.findDeclaredAttributeValue("dependsOnMethods");
- if (value != null) {
+ if (value != null && !TestNGUtil.isDisabled(annotation)) {
String text = value.getText();
if (value instanceof PsiReferenceExpression) {
final PsiElement resolve = ((PsiReferenceExpression)value).resolve();
@@ -84,10 +85,25 @@ public class DependsOnMethodInspection extends BaseJavaLocalInspectionTool
}
}
}
- Matcher matcher = PATTERN.matcher(text);
+ final Set<String> names = new HashSet<String>();
+ final Matcher matcher = PATTERN.matcher(text);
+ int idx = 0;
while (matcher.find()) {
- String methodName = matcher.group(1);
+ String methodName = matcher.group(1);
+ if (!names.add(methodName)) {
+ PsiAnnotationMemberValue element2Highlight = value;
+ if (value instanceof PsiArrayInitializerMemberValue) {
+ final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue)value).getInitializers();
+ if (idx < initializers.length) {
+ element2Highlight = initializers[idx];
+ }
+ }
+ problemDescriptors.add(manager.createProblemDescriptor(element2Highlight, "Duplicated method name: " + methodName,
+ (LocalQuickFix)null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
+ isOnTheFly));
+ }
checkMethodNameDependency(manager, psiClass, methodName, value, problemDescriptors, isOnTheFly);
+ idx++;
}
}
}
@@ -111,7 +127,19 @@ public class DependsOnMethodInspection extends BaseJavaLocalInspectionTool
} else {
final String configAnnotation = TestNGUtil.getConfigAnnotation(PsiTreeUtil.getParentOfType(value, PsiMethod.class));
- PsiMethod[] foundMethods = psiClass.findMethodsByName(methodName, true);
+ final PsiMethod[] foundMethods;
+ if (methodName.endsWith("*")) {
+ final String methodNameMask = StringUtil.trimEnd(methodName, "*");
+ final List<PsiMethod> methods = ContainerUtil.filter(psiClass.getMethods(), new Condition<PsiMethod>() {
+ @Override
+ public boolean value(PsiMethod method) {
+ return method.getName().startsWith(methodNameMask);
+ }
+ });
+ foundMethods = methods.toArray(new PsiMethod[methods.size()]);
+ } else {
+ foundMethods = psiClass.findMethodsByName(methodName, true);
+ }
if (foundMethods.length == 0) {
LOGGER.debug("dependsOnMethods method doesn't exist:" + methodName);
ProblemDescriptor descriptor = manager.createProblemDescriptor(value,
diff --git a/plugins/testng/src/com/theoryinpractice/testng/inspection/TestNGMethodNamingConventionInspection.java b/plugins/testng/src/com/theoryinpractice/testng/inspection/TestNGMethodNamingConventionInspection.java
new file mode 100644
index 000000000000..2cc894faf064
--- /dev/null
+++ b/plugins/testng/src/com/theoryinpractice/testng/inspection/TestNGMethodNamingConventionInspection.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.theoryinpractice.testng.inspection;
+
+import com.intellij.psi.PsiIdentifier;
+import com.intellij.psi.PsiMethod;
+import com.siyeh.ig.BaseInspectionVisitor;
+import com.siyeh.ig.InspectionGadgetsFix;
+import com.siyeh.ig.fixes.RenameFix;
+import com.siyeh.ig.naming.ConventionInspection;
+import com.siyeh.ig.psiutils.LibraryUtil;
+import com.siyeh.ig.psiutils.MethodUtils;
+import com.theoryinpractice.testng.util.TestNGUtil;
+import org.jetbrains.annotations.Nls;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class TestNGMethodNamingConventionInspection extends ConventionInspection {
+ @Nls
+ @NotNull
+ @Override
+ public String getDisplayName() {
+ return "TestNG test method naming convention";
+ }
+
+ @NotNull
+ @Override
+ protected String buildErrorString(Object... infos) {
+ final String methodName = (String)infos[0];
+ final int length = methodName.length();
+ if (length < getMinLength()) {
+ return "TestNG test method name <code>#ref</code> is too short (" + length + " < " + getMinLength() + ") #loc";
+ }
+ else if (length > getMaxLength()) {
+ return "TestNG test method name <code>#ref</code> is too long (" + length + " > " + getMaxLength() + ") #loc";
+ }
+ return "JUnit4 test method name <code>#ref</code> doesn't match regex '{0}' #loc";
+ }
+
+ @Override
+ protected String getDefaultRegex() {
+ return "[a-z][A-Za-z_\\d]*";
+ }
+
+ @Override
+ protected int getDefaultMinLength() {
+ return 4;
+ }
+
+ @Override
+ protected int getDefaultMaxLength() {
+ return 64;
+ }
+
+ @Override
+ protected InspectionGadgetsFix buildFix(Object... infos) {
+ return new RenameFix();
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new TestNGMethodNamingConventionVisitor();
+ }
+
+ private class TestNGMethodNamingConventionVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitMethod(PsiMethod method) {
+ super.visitMethod(method);
+ if (!TestNGUtil.hasTest(method)) {
+ return;
+ }
+ final PsiIdentifier nameIdentifier = method.getNameIdentifier();
+ if (nameIdentifier == null) {
+ return;
+ }
+ final String name = method.getName();
+ if (isValid(name)) {
+ return;
+ }
+ if (!isOnTheFly() && MethodUtils.hasSuper(method)) {
+ return;
+ }
+ if (LibraryUtil.isOverrideOfLibraryMethod(method)) {
+ return;
+ }
+ registerMethodError(method, name);
+ }
+ }
+}
diff --git a/plugins/testng/src/com/theoryinpractice/testng/model/TestNGRemoteListener.java b/plugins/testng/src/com/theoryinpractice/testng/model/TestNGRemoteListener.java
index cf8598d8ae3f..b4e89b28a5c6 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/model/TestNGRemoteListener.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/model/TestNGRemoteListener.java
@@ -48,10 +48,6 @@ public class TestNGRemoteListener implements IRemoteSuiteListener, IRemoteTestLi
public void onFinish(SuiteMessage suiteMessage) {
unboundOutputRoot.flush();
console.finish();
- final TestNGResults view = console.getResultsView();
- if (view != null) {
- view.finish();
- }
}
public void onStart(TestMessage tm) {
diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java b/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java
index ba30f43b66f0..9ea4429447fe 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/ui/ResultTreeRenderer.java
@@ -16,6 +16,7 @@
package com.theoryinpractice.testng.ui;
import com.intellij.execution.testframework.PoolOfTestIcons;
+import com.intellij.execution.testframework.TestFrameworkRunningModel;
import com.intellij.icons.AllIcons;
import com.intellij.ui.ColoredTreeCellRenderer;
import com.intellij.ui.SimpleTextAttributes;
@@ -34,10 +35,11 @@ import javax.swing.tree.DefaultMutableTreeNode;
*/
public class ResultTreeRenderer extends ColoredTreeCellRenderer
{
- private final TestNGConsoleProperties consoleProperties;
- public ResultTreeRenderer(TestNGConsoleProperties consoleProperties) {
- this.consoleProperties = consoleProperties;
+ private TestFrameworkRunningModel model;
+
+ public ResultTreeRenderer(TestFrameworkRunningModel model) {
+ this.model = model;
}
@Override
@@ -47,7 +49,7 @@ public class ResultTreeRenderer extends ColoredTreeCellRenderer
TestProxy proxy = ((TestNodeDescriptor) node.getUserObject()).getElement();
if (node == tree.getModel().getRoot()) {
TreeRootNode root = (TreeRootNode) proxy;
- if (node.getChildCount() == 0) {
+ if (node.getChildCount() == 0 && !((TestNGResults)model).hasFinishedTests()) {
if ((root.isStarted() && root.isInProgress()) || (root.isInProgress() && !root.isStarted())) {
setIcon(PoolOfTestIcons.NOT_RAN);
append("Instantiating tests... ", SimpleTextAttributes.REGULAR_ATTRIBUTES);
@@ -64,13 +66,13 @@ public class ResultTreeRenderer extends ColoredTreeCellRenderer
append(root.isInProgress() ? "Running tests..." : "Test Results", SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
- if (consoleProperties.isPaused()) {
+ if (model.getProperties().isPaused()) {
setIcon(AllIcons.RunConfigurations.TestPaused);
}
} else {
if (proxy.getResultMessage() != null) {
final TestResultMessage result = proxy.getResultMessage();
- final String name = TestProxy.toDisplayText(result, consoleProperties.getProject());
+ final String name = TestProxy.toDisplayText(result, model.getProperties().getProject());
append(name, SimpleTextAttributes.REGULAR_ATTRIBUTES);
} else {
append(proxy.getName(), SimpleTextAttributes.REGULAR_ATTRIBUTES);
diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java
index 442e03440ac5..78f980aea83d 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGResults.java
@@ -378,7 +378,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn
rootNode.setStarted(true);
}
- public void finish() {
+ public void finish(final boolean started) {
if (start > 0) {
end = System.currentTimeMillis();
}
@@ -409,6 +409,7 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn
}
}
tree.repaint();
+ TestsUIUtil.notifyByBalloon(project, started, rootNode, getProperties(), "in " + getTime());
}
});
}
@@ -466,6 +467,10 @@ public class TestNGResults extends TestResultsPanel implements TestFrameworkRunn
this.failedToStart = failedToStart;
}
+ public boolean hasFinishedTests() {
+ return count > 0;
+ }
+
private class OpenSourceSelectionListener implements TreeSelectionListener {
public void valueChanged(TreeSelectionEvent e) {
diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGTestTreeView.java b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGTestTreeView.java
index 48f252d828ee..7e5b7995af0c 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGTestTreeView.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/ui/TestNGTestTreeView.java
@@ -33,7 +33,7 @@ import javax.swing.tree.TreeSelectionModel;
public class TestNGTestTreeView extends TestTreeView {
protected TreeCellRenderer getRenderer(final TestConsoleProperties properties) {
- return new ResultTreeRenderer((TestNGConsoleProperties)properties);
+ return new ResultTreeRenderer(getTestFrameworkRunningModel());
}
public TestProxy getSelectedTest(@NotNull TreePath treepath) {
diff --git a/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java b/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java
index a3538059b1db..597bb5983876 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/ui/actions/RerunFailedTestsAction.java
@@ -8,25 +8,26 @@ import com.intellij.execution.actions.JavaRerunFailedTestsAction;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.AbstractTestProxy;
+import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComponentContainer;
+import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiModifier;
import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.util.containers.ContainerUtil;
import com.theoryinpractice.testng.configuration.SearchingForTestsTask;
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
import com.theoryinpractice.testng.configuration.TestNGRunnableState;
+import com.theoryinpractice.testng.util.TestNGUtil;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.net.ServerSocket;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class RerunFailedTestsAction extends JavaRerunFailedTestsAction {
@@ -53,6 +54,19 @@ public class RerunFailedTestsAction extends JavaRerunFailedTestsAction {
return new SearchingForTestsTask(serverSocket, config, tempFile, client) {
@Override
protected void fillTestObjects(final Map<PsiClass, Collection<PsiMethod>> classes) throws CantRunException {
+ final HashMap<PsiClass, Collection<PsiMethod>> fullClassList = ContainerUtil.newHashMap();
+ super.fillTestObjects(fullClassList);
+ for (final PsiClass aClass : fullClassList.keySet()) {
+ if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
+ @Override
+ public Boolean compute() {
+ return TestNGUtil.hasTest(aClass);
+ }
+ })) {
+ classes.put(aClass, fullClassList.get(aClass));
+ }
+ }
+
final GlobalSearchScope scope = config.getConfigurationModule().getSearchScope();
final Project project = config.getProject();
for (AbstractTestProxy proxy : failedTests) {
diff --git a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java
index c707a5e86e4e..565af249a27f 100644
--- a/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java
+++ b/plugins/testng/src/com/theoryinpractice/testng/util/TestNGUtil.java
@@ -113,25 +113,27 @@ public class TestNGUtil {
private static final String SUITE_TAG_NAME = "suite";
public static boolean hasConfig(PsiModifierListOwner element) {
- PsiMethod[] methods;
if (element instanceof PsiClass) {
- methods = ((PsiClass) element).getMethods();
+ for (PsiMethod method : ((PsiClass)element).getAllMethods()) {
+ if (isConfigMethod(method)) return true;
+ }
} else {
if (!(element instanceof PsiMethod)) return false;
- methods = new PsiMethod[] {(PsiMethod) element};
+ return isConfigMethod((PsiMethod)element);
}
+ return false;
+ }
- for (PsiMethod method : methods) {
- for (String fqn : CONFIG_ANNOTATIONS_FQN) {
- if (AnnotationUtil.isAnnotated(method, fqn, false)) return true;
- }
+ private static boolean isConfigMethod(PsiMethod method) {
+ for (String fqn : CONFIG_ANNOTATIONS_FQN) {
+ if (AnnotationUtil.isAnnotated(method, fqn, false)) return true;
+ }
- if (hasDocTagsSupport) {
- final PsiDocComment comment = method.getDocComment();
- if (comment != null) {
- for (String javadocTag : CONFIG_JAVADOC_TAGS) {
- if (comment.findTagByName(javadocTag) != null) return true;
- }
+ if (hasDocTagsSupport) {
+ final PsiDocComment comment = method.getDocComment();
+ if (comment != null) {
+ for (String javadocTag : CONFIG_JAVADOC_TAGS) {
+ if (comment.findTagByName(javadocTag) != null) return true;
}
}
}
@@ -178,13 +180,7 @@ public class TestNGUtil {
if (checkDisabled) {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(element, true, TEST_ANNOTATION_FQN);
if (annotation != null) {
- PsiNameValuePair[] attribs = annotation.getParameterList().getAttributes();
- for (PsiNameValuePair attrib : attribs) {
- final String attribName = attrib.getName();
- final PsiAnnotationMemberValue attribValue = attrib.getValue();
- if (Comparing.strEqual(attribName, "enabled") && attribValue != null && attribValue.textMatches("false"))
- return false;
- }
+ if (isDisabled(annotation)) return false;
}
}
return true;
@@ -207,7 +203,7 @@ public class TestNGUtil {
if (AnnotationUtil.isAnnotated(psiClass, TEST_ANNOTATION_FQN, true, true)) {
//even if it has a global test, we ignore private methods
boolean isPrivate = element.hasModifierProperty(PsiModifier.PRIVATE);
- return !isPrivate;
+ return !isPrivate && !element.hasModifierProperty(PsiModifier.STATIC) && !hasConfig(element);
}
if (hasTestJavaDoc(psiClass, checkJavadoc)) return true;
}
@@ -215,6 +211,11 @@ public class TestNGUtil {
return false;
}
+ public static boolean isDisabled(PsiAnnotation annotation) {
+ final PsiAnnotationMemberValue attributeValue = annotation.findDeclaredAttributeValue("enabled");
+ return attributeValue != null && attributeValue.textMatches("false");
+ }
+
private static boolean hasTestJavaDoc(@NotNull PsiDocCommentOwner element, final boolean checkJavadoc) {
if (checkJavadoc) {
return getTextJavaDoc(element) != null;
diff --git a/plugins/testng/src/inspectionDescriptions/TestNGMethodNamingConvention.html b/plugins/testng/src/inspectionDescriptions/TestNGMethodNamingConvention.html
new file mode 100644
index 000000000000..2303a201c5d9
--- /dev/null
+++ b/plugins/testng/src/inspectionDescriptions/TestNGMethodNamingConvention.html
@@ -0,0 +1,13 @@
+<html>
+<body>
+Reports TestNG test methods whose names are either too short, too long, or do not follow the specified regular expression pattern.
+When this inspection is enabled, the <i>Instance method naming convention</i> inspection
+will ignore TestNG test methods automatically.
+<!-- tooltip end -->
+<p>
+ Use the fields below to specify minimum length, maximum length and regular expression expected for TestNG test method names.
+ Specify <b>0</b> to not check the length of names. Regular expressions are in standard <b>java.util.regex</b> format.
+<p>
+ <small>New in 14</small>
+</body>
+</html> \ No newline at end of file