aspose file tools*
The moose likes Testing and the fly likes @BeforeClass not working in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "@BeforeClass not working in Eclipse" Watch "@BeforeClass not working in Eclipse" New topic
Author

@BeforeClass not working in Eclipse

Chris Voge
Ranch Hand

Joined: Jul 25, 2005
Posts: 34
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
Could you post the full test class for us to see? (perhaps with just one test method and without its method body)


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Chris Voge
Ranch Hand

Joined: Jul 25, 2005
Posts: 34
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Jul 25, 2005
Posts: 34
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

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Jul 25, 2005
Posts: 34
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30546
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: @BeforeClass not working in Eclipse