File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@BeforeClass not working in Eclipse

 
Chris Voge
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

We are using JUnit4 on IBM's Rational Software Architect
version 7.0.0.2 using Eclipse version 3.2 ( I believe ).

It looks like the @BeforeClass annotation method does not
get executed using Eclipse. I'm not sure whats
going on. I tried it with and without this method:

public static junit.framework.Test suite() {
return new JUnit4TestAdapter(PolicyBOPTest.class);
}



Have any of you encountered this and found a solution ?
Any info would be appreciated. Thanks

Chris
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you post the full test class for us to see? (perhaps with just one test method and without its method body)
 
Chris Voge
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI, The regular @Before and @After methods work fine.


package com.gmrc.domain.auto;

import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.gmrc.domain.common.CommercialPolicy;
import com.gmrc.testSetupUtils.SetupTestAutoPolicy;
import com.msiinet.MsiException;
import servletunit.struts.CactusStrutsTestCase;

public class PolicyAutoTest extends CactusStrutsTestCase {

private static CommercialPolicy testCp;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
testCp = SetupTestAutoPolicy.populateTestAutoPolicy();
}

/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
if (testCp != null)
testCp.delete(false, true);
}

/* (non-Javadoc)
* @see servletunit.struts.CactusStrutsTestCase#setUp()
*/
@Before
protected void setUp() throws Exception {
super.setUp();
testCp = SetupTestAutoPolicy.populateTestAutoPolicy(5);
}

/* (non-Javadoc)
* @see servletunit.struts.CactusStrutsTestCase#tearDown()
*/
@After
protected void tearDown() throws Exception {
super.tearDown();
if (testCp != null)
testCp.delete(false, true);
}
/**
* Test method for {@link com.gmrc.domain.auto.PolicyAuto#getAllPPVehicles()}.
*/
@Test
public void testDoesPolicyHavePPVehicles() throws MsiException{
//Just making sure that a valid commercial policy is present.
assertNotNull("Commercial Policy is null ", testCp);

List ppVehicles = testCp.getPolicyAuto().getAllPPVehicles();

assertFalse("Found private passenger vehicles ", ppVehicles.size()>0);
}

}


Thanks Chris
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess would be that the problem is due to your class extending from TestCase (indirectly through CactusStrutsTestCase).

For example, try running this class with and without "extends TestCase":
 
Chris Voge
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That seemed to do the trick. However, now I'm getting
a different error.

javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.

I've seen executing the launchClient.bat file might be able to resolve this, but I'm not real familiar with it. Any other ideas ?

Thanks, Chris
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This sounds like it might be server-specific. Which application server are you running against?

Could you figure out what kind of a JNDI URL your test is trying to connect with and post that to the respective product's forum.
 
Chris Voge
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm on Websphere 6.1

I posted my issue in the Websphere forum.

http://www.coderanch.com/t/78603/Websphere/ConfigurationException

Thanks for your help.

Chris
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33720
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,
This is happening because you are no longer extending CactusTestCase. You could try instantiating a CactusTestCase and calling its setUp/tearDown methods from within @Before and @After. Or you could write a JUnit 3.8 style test and keep the superclass.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic