You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jt...@apache.org on 2020/06/22 07:06:05 UTC

[netbeans] branch master updated: NB JUnit Ignore annotation support

This is an automated email from the ASF dual-hosted git repository.

jtulach pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 47bc867  NB JUnit Ignore annotation support
     new cc9447c  Merge pull request #2185 from hectorespert/nbjunit_ignore_tag
47bc867 is described below

commit 47bc86772d9bc6123c0ed216ccd8d151c6a2da9b
Author: Hector Espert <he...@gmail.com>
AuthorDate: Sat Jun 13 14:14:51 2020 +0200

    NB JUnit Ignore annotation support
---
 .travis.yml                                        |   4 +-
 harness/nbjunit/apichanges.xml                     |  14 ++
 harness/nbjunit/manifest.mf                        |   3 +-
 harness/nbjunit/nbproject/project.properties       |   2 +-
 .../nbjunit/src/org/netbeans/junit/NbTestCase.java |  18 ++-
 .../src/org/netbeans/junit/RandomlyFails.java      |   4 +
 .../unit/src/org/netbeans/junit/IgnoreTest.java    | 174 +++++++++++++++++++++
 .../junit/NbModuleSuiteContextClassLoaderTest.java |   3 +-
 .../src/org/netbeans/junit/RandomlyFailsTest.java  |   2 +-
 .../src/org/netbeans/libs/junit4/JunitTest.java    |  43 +++++
 10 files changed, 259 insertions(+), 8 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index afdce8f..43acb0f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -97,12 +97,11 @@ matrix:
         - name: Test harness modules
           jdk: openjdk8
           env:
-            - OPTS="-silent -Dcluster.config=platform -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true -Dvanilla.javac.exists=true"
+            - OPTS="-quiet -Dcluster.config=platform -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true -Dvanilla.javac.exists=true"
           before_script:
             - ant $OPTS clean
             - ant $OPTS build
           script:
-            - OPTS="-quiet -Dcluster.config=platform -Djavac.compilerargs=-nowarn -Dbuild.compiler.deprecation=false -Dtest-unit-sys-prop.ignore.random.failures=true -Dvanilla.javac.exists=true"
             - ant $OPTS -f harness/o.n.insane test
             - ant $OPTS -f harness/apisupport.harness test
             - ant $OPTS -f harness/nbjunit test
@@ -149,6 +148,7 @@ matrix:
             - hide-logs.sh ant $OPTS -f platform/keyring.impl test
             - hide-logs.sh ant $OPTS -f platform/lib.uihandler test
             - hide-logs.sh ant $OPTS -f platform/libs.javafx test
+            - hide-logs.sh ant $OPTS -f platform/libs.junit4 test
             - travis_retry hide-logs.sh ant $OPTS -f platform/masterfs test
             - hide-logs.sh ant $OPTS -f platform/masterfs.linux test
             - hide-logs.sh ant $OPTS -f platform/netbinox test  -Dtest.config=stableBTD
diff --git a/harness/nbjunit/apichanges.xml b/harness/nbjunit/apichanges.xml
index a4aa770..bfa2fde 100644
--- a/harness/nbjunit/apichanges.xml
+++ b/harness/nbjunit/apichanges.xml
@@ -34,6 +34,20 @@
     <!-- ACTUAL CHANGES BEGIN HERE: -->
 
 <changes>
+    <change id="ignore.support">
+        <api name="nbjunit"/>
+        <summary>JUnit ignore annotation</summary>
+        <version major="1" minor="98"/>
+        <date day="21" month="6" year="2020"/>
+        <author login="hectorespert"/>
+        <compatibility addition="yes"/>
+        <description>
+            <p>
+                Add support for JUnit <a href="http://junit.sourceforge.net/javadoc/org/junit/Ignore.html">@Ignore</a> annotation on NbTestCase test case extension.
+            </p>
+        </description>
+        <class package="org.netbeans.junit" name="NbTestCase"/>
+    </change>
     <change id="NbModuleSuite.Configuration.parentClassLoader">
         <api name="nbjunit"/>
         <summary>NbModuleSuite.Configuration.parentClassLoader()</summary>
diff --git a/harness/nbjunit/manifest.mf b/harness/nbjunit/manifest.mf
index a69f4a2..a025f1d 100644
--- a/harness/nbjunit/manifest.mf
+++ b/harness/nbjunit/manifest.mf
@@ -1,5 +1,4 @@
 Manifest-Version: 1.0
 OpenIDE-Module: org.netbeans.modules.nbjunit/1
 OpenIDE-Module-Localizing-Bundle: org/netbeans/junit/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.97
-
+OpenIDE-Module-Specification-Version: 1.98
diff --git a/harness/nbjunit/nbproject/project.properties b/harness/nbjunit/nbproject/project.properties
index e26c817..cbe11c7 100644
--- a/harness/nbjunit/nbproject/project.properties
+++ b/harness/nbjunit/nbproject/project.properties
@@ -16,7 +16,7 @@
 # under the License.
 
 javac.compilerargs=-Xlint:unchecked
-javac.source=1.6
+javac.source=1.8
 javadoc.arch=${basedir}/arch.xml
 javadoc.apichanges=${basedir}/apichanges.xml
 
diff --git a/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java b/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java
index 214508b..b7ee78d 100644
--- a/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java
+++ b/harness/nbjunit/src/org/netbeans/junit/NbTestCase.java
@@ -34,7 +34,6 @@ import java.io.PrintStream;
 import java.lang.management.LockInfo;
 import java.lang.management.ManagementFactory;
 import java.lang.management.MonitorInfo;
-import java.lang.management.PlatformLoggingMXBean;
 import java.lang.management.RuntimeMXBean;
 import java.lang.management.ThreadInfo;
 import java.lang.management.ThreadMXBean;
@@ -62,6 +61,7 @@ import java.util.regex.Pattern;
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 import junit.framework.TestResult;
+import org.junit.Ignore;
 import org.netbeans.insane.live.LiveReferences;
 import org.netbeans.insane.live.Path;
 import org.netbeans.insane.scanner.CountingVisitor;
@@ -129,6 +129,22 @@ public abstract class NbTestCase extends TestCase implements NbTest {
      * @return true if the test can run
      */
     public @Override boolean canRun() {
+        if (getClass().isAnnotationPresent(Ignore.class)) {
+            String message = getClass().getAnnotation(Ignore.class).value();
+            System.err.println("Skipping " + getClass().getName() + (message.isEmpty() ? "" : ": " + message));
+            return false;
+        }
+        
+        try {
+            if (getClass().getMethod(getName()).isAnnotationPresent(Ignore.class)) {
+                String message = getClass().getMethod(getName()).getAnnotation(Ignore.class).value();
+                System.err.println("Skipping " + getClass().getName() + "." + getName() + (message.isEmpty() ? "" : ": " + message));
+                return false;
+            }
+        } catch (NoSuchMethodException x) {
+            // Specially named methods; let it pass.
+        }
+        
         if (NbTestSuite.ignoreRandomFailures()) {
             if (getClass().isAnnotationPresent(RandomlyFails.class)) {
                 System.err.println("Skipping " + getClass().getName());
diff --git a/harness/nbjunit/src/org/netbeans/junit/RandomlyFails.java b/harness/nbjunit/src/org/netbeans/junit/RandomlyFails.java
index 204d063..d3fbd36 100644
--- a/harness/nbjunit/src/org/netbeans/junit/RandomlyFails.java
+++ b/harness/nbjunit/src/org/netbeans/junit/RandomlyFails.java
@@ -36,6 +36,10 @@ import java.lang.annotation.Target;
  * <p>Test runs which must be reliable should define the system property.
  * (E.g. for NetBeans modules: <code>ant -Dtest-unit-sys-prop.ignore.random.failures=true test</code>)
  * Developers running tests interactively should not.
+ * 
+ * JUnit {@literal @}Ignore annotation is supported.
+ * {@literal @}Ignore annotation is recommended to mark tests that are broken instead this annotation.
+ * 
  * @since 1.51
  */
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/harness/nbjunit/test/unit/src/org/netbeans/junit/IgnoreTest.java b/harness/nbjunit/test/unit/src/org/netbeans/junit/IgnoreTest.java
new file mode 100644
index 0000000..6849130
--- /dev/null
+++ b/harness/nbjunit/test/unit/src/org/netbeans/junit/IgnoreTest.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.netbeans.junit;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import static junit.framework.TestCase.assertEquals;
+import junit.framework.TestResult;
+import junit.runner.BaseTestRunner;
+import junit.textui.TestRunner;
+import org.junit.Ignore;
+
+/**
+ * Test JUnit @Ignore annotation support 
+ * @author Hector Espert
+ */
+public class IgnoreTest extends TestCase {
+
+    public void testNbTestCase() throws Exception {
+        assertTestClass(BasicTestCase.class, 3, 1, 1);
+        assertTestClass(IgnoredTestCase.class, 0, 0, 0);
+        assertTestClass(IgnoredTestCaseWithMessage.class, 0, 0, 0);
+        assertTestClass(IgnoredMethodTestCase.class, 2, 1, 0);
+        assertTestClass(IgnoredMethodTestCaseWithMessage.class, 1, 0, 0);
+    }
+    
+    public void testNbTestSuite() throws Exception {
+        assertTestClass(BasicTestSuite.class, 3, 1, 1);
+        assertTestClass(IgnoredTestSuite.class, 0, 0, 0);
+        assertTestClass(IgnoredMethodTestSuite.class, 3, 1, 0);
+    }
+    
+    private void assertTestClass(Class testClass, int runCount, int failures, int errors) {
+        BaseTestRunner runner = new TestRunner();
+        TestResult result = new TestResult();
+        runner.getTest(testClass.getName()).run(result);
+        assertEquals(runCount, result.runCount());
+        assertEquals(failures, result.failureCount());
+        assertEquals(errors, result.errorCount());
+    }
+    
+    public static class BasicTestCase extends NbTestCase {
+        
+        public BasicTestCase(String n) {
+            super(n);
+        }
+        
+        public void testSuccesful() {
+            assertTrue(true);
+        }
+        
+        public void testFailed() {
+            fail();
+        }
+        
+        public void testError() {
+            throw new RuntimeException();
+        }
+        
+    }
+    
+    @Ignore
+    public static class IgnoredTestCase extends NbTestCase {
+        
+        public IgnoredTestCase(String n) {
+            super(n);
+        }
+        
+        public void testSuccesful() {
+            assertTrue(true);
+        }
+        
+        public void testFailed() {
+            fail();
+        }
+        
+        public void testError() {
+            throw new RuntimeException();
+        }
+        
+    }
+    
+    @Ignore("Ignored test case")
+    public static class IgnoredTestCaseWithMessage extends NbTestCase {
+        
+        public IgnoredTestCaseWithMessage(String n) {
+            super(n);
+        }
+        
+        public void testFailed() {
+            fail();
+        }
+
+    }
+    
+    public static class IgnoredMethodTestCase extends NbTestCase {
+        
+        public IgnoredMethodTestCase(String n) {
+            super(n);
+        }
+        
+        public void testSuccesful() {
+            assertTrue(true);
+        }
+        
+        public void testFailed() {
+            fail();
+        }
+        
+        @Ignore
+        public void testIgnored() {
+            fail("Test method should be ignored");
+        }
+        
+    }
+    
+    public static class IgnoredMethodTestCaseWithMessage extends NbTestCase {
+        
+        public IgnoredMethodTestCaseWithMessage(String n) {
+            super(n);
+        }
+        
+        public void testSuccesful() {
+            assertTrue(true);
+        }
+
+        @Ignore("Ignored method with message")
+        public void testIgnored() {
+            fail("Test method should be ignored");
+        }
+        
+    }
+    
+    public static class BasicTestSuite extends TestCase {
+        public static Test suite() {
+            return new NbTestSuite(BasicTestCase.class);
+        }
+    }
+    
+    public static class IgnoredTestSuite extends TestCase {
+        public static Test suite() {
+            NbTestSuite suite = new NbTestSuite();
+            suite.addTestSuite(IgnoredTestCase.class);
+            suite.addTestSuite(IgnoredTestCaseWithMessage.class);
+            return suite;
+        }
+    }
+    
+    public static class IgnoredMethodTestSuite extends TestCase {
+        public static Test suite() {
+            NbTestSuite suite = new NbTestSuite();
+            suite.addTestSuite(IgnoredMethodTestCase.class);
+            suite.addTestSuite(IgnoredMethodTestCaseWithMessage.class);
+            return suite;
+        }
+    }
+    
+}
diff --git a/harness/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteContextClassLoaderTest.java b/harness/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteContextClassLoaderTest.java
index 8d61c58..4dc510d 100644
--- a/harness/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteContextClassLoaderTest.java
+++ b/harness/nbjunit/test/unit/src/org/netbeans/junit/NbModuleSuiteContextClassLoaderTest.java
@@ -26,7 +26,8 @@ import test.pkg.not.in.junit.NbModuleSuiteT;
  * @author Jaroslav Tulach <jt...@netbeans.org>
  */
 public class NbModuleSuiteContextClassLoaderTest extends NbTestCase {
-    static ClassLoader before;
+    
+    private static ClassLoader before;
     
     public NbModuleSuiteContextClassLoaderTest(String name) {
         super(name);
diff --git a/harness/nbjunit/test/unit/src/org/netbeans/junit/RandomlyFailsTest.java b/harness/nbjunit/test/unit/src/org/netbeans/junit/RandomlyFailsTest.java
index 07d8c5c..b2f2995 100644
--- a/harness/nbjunit/test/unit/src/org/netbeans/junit/RandomlyFailsTest.java
+++ b/harness/nbjunit/test/unit/src/org/netbeans/junit/RandomlyFailsTest.java
@@ -83,7 +83,7 @@ public class RandomlyFailsTest extends TestCase {
     }
 
     private void run(Class... tests) {
-        runs = new ArrayList<Integer>();
+        runs = new ArrayList<>();
         BaseTestRunner runner = new TestRunner();
         for (Class test : tests) {
             TestResult result = new TestResult();
diff --git a/platform/libs.junit4/test/unit/src/org/netbeans/libs/junit4/JunitTest.java b/platform/libs.junit4/test/unit/src/org/netbeans/libs/junit4/JunitTest.java
new file mode 100644
index 0000000..2cac624
--- /dev/null
+++ b/platform/libs.junit4/test/unit/src/org/netbeans/libs/junit4/JunitTest.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.netbeans.libs.junit4;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * @author Hector Espert
+ */
+public class JunitTest {
+    
+    @Test
+    public void assertObject() {
+        Object object = new Object();
+        assertNotNull("Object shouldn't be null", object);
+    }
+    
+    @Test
+    @Ignore
+    public void ignoreTestMethod() {
+        fail("This method should be ignored");
+    }
+    
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists