On 10/19/07, Ana Belén Antón Gironés <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> I have a problem with the test of my application. The tearDown() test
> fails,
> and I don't know what is happening. When I run my JUnit test I get this
> message:
>
> java.lang.NullPointerException
> at eu.services.information.tests.ISTestCase.tearDown(ISTestCase.java:25)
> at junit.framework.TestCase.runBare(TestCase.java:136)
> 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:120)
> at junit.framework.TestSuite.runTest(TestSuite.java:228)
> at junit.framework.TestSuite.run(TestSuite.java:223)
> at
> org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java
> :35
> )
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
> (JUnit4TestRef
> erence.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java
> :3
> 8)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRu
> nner.java:460)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
> (RemoteTestRu
> nner.java:673)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
> (RemoteTestRunner.
> java:386)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
> (RemoteTestRunner
> .java:196)
>
>
> My test is:
>
> ==================================================================
> package eu.services.information.tests;
>
> import junit.framework.TestCase;
> import org.apache.tuscany.sca.host.embedded.SCADomain;
> import eu.services.information.is.InformationService;
>
> /**
> * This shows how to test the IGS component.
> */
> public class ISTestCase extends TestCase {
>
>     private InformationService is;
>     private SCADomain scaDomain;
>
>     @Override
>     protected void setUp() throws Exception {
>      SCADomain scaDomain = SCADomain.newInstance("Information.composite");
>         is = scaDomain.getService(InformationService.class,
>   "InformationServiceComponent");
>     }
>
>     @Override
>     protected void tearDown() throws Exception {
>         scaDomain.close();
>     }
>
>     public void testIS() throws Exception {
>
> assertEquals(is.getInformationObject("myInformationObject").getText(),
> "myTest");
>         assertEquals(is.getInformationObject
> ("myInformationObject").getId(),
> "myId");
>     }
> }
> ===================================================================
>
> Have you got any idea about what is wrong? Thanks in advance!!
>
> Ana Belen.
>
Hi Ana Belen

I quite often see this when there is some exception in the setUp phase that
isn't caught and printed out. The result is that scaDomain remains null and
hence JUnit calls tearDown() and calling scaDomain.close() causes a null
pointer exception. Try putting a try/catch around the code in setUp and
print out any exceptions that are thrown.

Hope that helps

Simon

Reply via email to