summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-l10n-en-plugin/src/main
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-04-27 14:45:13 +0200
committerDavid Gageot <david@gageot.net>2012-04-27 14:59:00 +0200
commit1a6a18a5c4e73987a72b8176f398477f13074d29 (patch)
tree6b0521a1eabf0bee1264ff38d2b8ea20f4044b52 /plugins/sonar-l10n-en-plugin/src/main
parent12c43f766d3c1dfd5217388b6648ce9114f42baa (diff)
downloadsonarqube-1a6a18a5c4e73987a72b8176f398477f13074d29.tar.gz
sonarqube-1a6a18a5c4e73987a72b8176f398477f13074d29.zip
SONAR 1076 - Run PMD on Unit Tests
Diffstat (limited to 'plugins/sonar-l10n-en-plugin/src/main')
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd.properties10
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitAssertionsShouldIncludeMessage.html8
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitSpelling.html9
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitStaticSuite.html9
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitTestsShouldIncludeAssert.html10
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/SimplifyBooleanAssertion.html9
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/TestClassWithoutTestCases.html9
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UnnecessaryBooleanAssertion.html7
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertEqualsInsteadOfAssertTrue.html10
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertNullInsteadOfAssertTrue.html13
-rw-r--r--plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertSameInsteadOfAssertTrue.html11
11 files changed, 105 insertions, 0 deletions
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd.properties b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd.properties
index 6c780de2d15..167b7897d1e 100644
--- a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd.properties
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd.properties
@@ -275,3 +275,13 @@ rule.pmd.UseConcurrentHashMap.name=Use ConcurrentHashMap
rule.pmd.DoNotHardCodeSDCard.name=Android - Do Not Hard Code SD Card
rule.pmd.DontCallThreadRun.name=Dont Call Thread Run
rule.pmd.GuardDebugLogging.name=Guard Debug Logging
+rule.pmd-unit-tests.JUnitStaticSuite.name=JUnit static suite
+rule.pmd-unit-tests.JUnitSpelling.name= JUnit spelling
+rule.pmd-unit-tests.JUnitAssertionsShouldIncludeMessage.name=JUnit assertions should include a message
+rule.pmd-unit-tests.JUnitTestsShouldIncludeAssert.name=JUnit tests should include an assert
+rule.pmd-unit-tests.TestClassWithoutTestCases.name=Test class without test cases
+rule.pmd-unit-tests.UnnecessaryBooleanAssertion.name=Unnecessary boolean assertion
+rule.pmd-unit-tests.UseAssertEqualsInsteadOfAssertTrue.name=Use assertEquals instead of assertTrue
+rule.pmd-unit-tests.UseAssertSameInsteadOfAssertTrue.name=Use assertSame instead of assertTrue
+rule.pmd-unit-tests.UseAssertNullInsteadOfAssertTrue.name=Use assertNull instead of assertTrue
+rule.pmd-unit-tests.SimplifyBooleanAssertion.name=Simplify boolean assertion
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitAssertionsShouldIncludeMessage.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitAssertionsShouldIncludeMessage.html
new file mode 100644
index 00000000000..ec742d69cc4
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitAssertionsShouldIncludeMessage.html
@@ -0,0 +1,8 @@
+JUnit assertions should include a message - i.e., use the three argument version of assertEquals(), not the two argument version.
+<pre>
+public class Foo extends TestCase {
+ public void testSomething() {
+ assertEquals("foo", "bar"); // violation, should be assertEquals("Foo does not equals bar", "foo", "bar");
+ }
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitSpelling.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitSpelling.html
new file mode 100644
index 00000000000..48bdfb21fa3
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitSpelling.html
@@ -0,0 +1,9 @@
+Some JUnit framework methods are easy to misspell.
+<pre>
+import junit.framework.*;
+
+public class Foo extends TestCase {
+ public void setup() {} // violation, should be setUp()
+ public void TearDown() {} // violation, should be tearDown()
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitStaticSuite.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitStaticSuite.html
new file mode 100644
index 00000000000..916d6dea758
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitStaticSuite.html
@@ -0,0 +1,9 @@
+The suite() method in a JUnit test needs to be both public and static.
+<pre>
+import junit.framework.*;
+
+public class Foo extends TestCase {
+ public void suite() {} // violation, should be static
+ private static void suite() {} // violation, should be public
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitTestsShouldIncludeAssert.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitTestsShouldIncludeAssert.html
new file mode 100644
index 00000000000..ad6b1256de4
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/JUnitTestsShouldIncludeAssert.html
@@ -0,0 +1,10 @@
+JUnit tests should include at least one assertion. This makes the tests more robust, and using assert with messages provide the developer a clearer idea of what the test does.
+<pre>
+public class Foo extends TestCase {
+ public void testSomething() {
+ Bar b = findBar();
+ b.work();
+ // violation, we could use assertNotNull("bar not found", b);
+ }
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/SimplifyBooleanAssertion.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/SimplifyBooleanAssertion.html
new file mode 100644
index 00000000000..093b4fcef89
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/SimplifyBooleanAssertion.html
@@ -0,0 +1,9 @@
+Avoid negation in an assertTrue or assertFalse test. For example, rephrase: assertTrue(!expr); as: assertFalse(expr);
+<pre>
+public class SimpleTest extends TestCase {
+ public void testX() {
+ assertTrue("not empty", !r.isEmpty()); // violation, replace with assertFalse("not empty", r.isEmpty())
+ assertFalse(!r.isEmpty()); // violation, replace with assertTrue("empty", r.isEmpty())
+ }
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/TestClassWithoutTestCases.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/TestClassWithoutTestCases.html
new file mode 100644
index 00000000000..891dde75b7f
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/TestClassWithoutTestCases.html
@@ -0,0 +1,9 @@
+Test classes end with the suffix Test. Having a non-test class with that name is not a good practice, since most people will assume it is a test case. Test classes have test methods named testXXX.
+<pre>
+public class CarTest { // violation, consider changing the name of the class if it is not a test
+ // consider adding test methods if it is a test
+ public static void main(String[] args) {
+ // do something
+ }
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UnnecessaryBooleanAssertion.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UnnecessaryBooleanAssertion.html
new file mode 100644
index 00000000000..83356d46679
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UnnecessaryBooleanAssertion.html
@@ -0,0 +1,7 @@
+A JUnit test assertion with a boolean literal is unnecessary since it always will eval to the same thing. Consider using flow control (in case of assertTrue(false) or similar) or simply removing statements like assertTrue(true) and assertFalse(false). If you just want a test to halt, use the fail method.
+<pre>
+public class SimpleTest extends TestCase {
+ public void testX() {
+ assertTrue(true); // violation
+ }
+}</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertEqualsInsteadOfAssertTrue.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertEqualsInsteadOfAssertTrue.html
new file mode 100644
index 00000000000..0887fb74827
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertEqualsInsteadOfAssertTrue.html
@@ -0,0 +1,10 @@
+This rule detects JUnit assertions in object equality. These assertions should be made by more specific methods, like assertEquals.
+<pre>
+public class FooTest extends TestCase {
+ void testCode() {
+ Object a, b;
+
+ assertTrue(a.equals(b)); // violation
+ assertEquals("a should equals b", a, b); // good usage
+ }
+}</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertNullInsteadOfAssertTrue.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertNullInsteadOfAssertTrue.html
new file mode 100644
index 00000000000..947ebd5bde9
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertNullInsteadOfAssertTrue.html
@@ -0,0 +1,13 @@
+This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertNull, assertNotNull.
+<pre>
+public class FooTest extends TestCase {
+ void testCode() {
+ Object a = doSomething();
+
+ assertTrue(a==null); // violation
+ assertNull(a); // good usage
+ assertTrue(a != null); // violation
+ assertNotNull(a); // good usage
+ }
+}
+</pre> \ No newline at end of file
diff --git a/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertSameInsteadOfAssertTrue.html b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertSameInsteadOfAssertTrue.html
new file mode 100644
index 00000000000..d2d317b37f8
--- /dev/null
+++ b/plugins/sonar-l10n-en-plugin/src/main/resources/org/sonar/l10n/pmd/rules/pmd-unit-tests/UseAssertSameInsteadOfAssertTrue.html
@@ -0,0 +1,11 @@
+This rule detects JUnit assertions in object references equality. These assertions should be made by more specific methods, like assertSame, assertNotSame.
+<pre>
+public class FooTest extends TestCase {
+ void testCode() {
+ Object a, b;
+
+ assertTrue(a==b); // violation
+ assertSame(a, b); // good usage
+ }
+}
+</pre> \ No newline at end of file