Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

@BeforeClass not working in Eclipse

 
Ranch Hand
Posts: 34
  • 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
 
author
Posts: 11962
5
  • 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
  • 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
Posts: 11962
5
  • 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
  • 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
Posts: 11962
5
  • 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
  • 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.

https://coderanch.com/t/78603/Websphere/ConfigurationException

Thanks for your help.

Chris
 
author & internet detective
Posts: 40035
809
Eclipse IDE VI Editor Java
  • 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.
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic