dev@glassfish.java.net

Re: junit _at_Test(expected=...) not working

From: Lloyd L Chambers <Lloyd.Chambers_at_Sun.COM>
Date: Thu, 17 Apr 2008 13:50:03 -0700

Apparently @Test.expected() does not work. This test should succeed,
since it is expected() that an IllegalArgumentException will be thrown.


     @Test(expected=IllegalArgumentException.class)
     public void testForBrokenJUnit() {
         throw new IllegalArgumentException( "expected" );
     }

Running org.glassfish.admin.amx.test.SingletonEnforcerTest
Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.018
sec <<< FAILURE!

Tests in error:
    
testForBrokenJUnit(org.glassfish.admin.amx.test.SingletonEnforcerTest)

................

-------------------------------------------------------------------------------
Test set: org.glassfish.admin.amx.test.SingletonEnforcerTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.019
sec <<< FAILURE!
testForBrokenJUnit
(org.glassfish.admin.amx.test.SingletonEnforcerTest) Time elapsed:
0.003 sec <<< ERROR!
java.lang.IllegalArgumentException: expected
        at
org
.glassfish
.admin
.amx
.test
.SingletonEnforcerTest.testForBrokenJUnit(SingletonEnforcerTest.java:56)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
        at
sun
.reflect
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at junit.framework.TestCase.runTest(TestCase.java:168)
        at junit.framework.TestCase.runBare(TestCase.java:134)
        at junit.framework.TestResult$1.protect(TestResult.java:110)
        at junit.framework.TestResult.runProtected(TestResult.java:128)
        at junit.framework.TestResult.run(TestResult.java:113)
        at junit.framework.TestCase.run(TestCase.java:124)
        at junit.framework.TestSuite.runTest(TestSuite.java:232)
        at junit.framework.TestSuite.run(TestSuite.java:227)
        at
org
.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:
76)
        at
org
.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:
62)
        at
org
.apache
.maven
.surefire
.suite
.AbstractDirectoryTestSuite
.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at
org
.apache
.maven
.surefire
.suite
.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
        at
sun
.reflect
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at
org
.apache
.maven
.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:
338)
        at
org
.apache.maven.surefire.booter.SurefireBooter.run(SurefireBooter.java:
241)
        at
org
.apache
.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:492)
        at
org
.apache
.maven
.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:443)
        at
org
.apache
.maven
.lifecycle
.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:
539)
        at
org
.apache
.maven
.lifecycle
.DefaultLifecycleExecutor
.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480)
        at
org
.apache
.maven
.lifecycle
.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:459)
        at
org
.apache
.maven
.lifecycle
.DefaultLifecycleExecutor
.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311)
        at
org
.apache
.maven
.lifecycle
.DefaultLifecycleExecutor
.executeTaskSegments(DefaultLifecycleExecutor.java:278)
        at
org
.apache
.maven
.lifecycle
.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:280)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
        at
sun
.reflect
.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:
430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

MB2:amx-impl lloyd$



On Apr 17, 2008, at 1:44 PM, Lloyd L Chambers wrote:
> I have a unit test with:
>
> @Test(expected=IllegalArgumentException.class)
>
> When the test is run as part of the build, an
> IllegalArgumentException is thrown, and the test is marked as failed!
>
> Is the V3 run environment not checking for expected() failures?
>
> Lloyd
> ---
> Lloyd L Chambers
> lloyd.chambers_at_sun.com
> Sun Microsystems, Inc
>
>
>

---
Lloyd L Chambers
lloyd.chambers_at_sun.com
Sun Microsystems, Inc