junit.framework.AssertionFailedError: TestCase.getName() cannot be null

248 views
Skip to first unread message

dhavaly2k

unread,
Mar 20, 2008, 2:52:31 PM3/20/08
to testng-users
I am using simple test class for testing my DAO. I am extending
AbstractJpaTests.
I am using spring 2.5 and testNG 5.7-jdk 1.5

[testng] FAILED CONFIGURATION: @BeforeTest launchSetup
[testng] junit.framework.AssertionFailedError: TestCase.getName()
cannot be null
[testng] at junit.framework.Assert.fail(Assert.java:47)
[testng] at junit.framework.Assert.assertTrue(Assert.java:20)
[testng] at junit.framework.Assert.assertNotNull(Assert.java:214)
[testng] at
org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.getTestMethod(AbstractAnnotationAwareTransactionalTests.java:
226)
[testng] at
org.springframework.test.annotation.AbstractAnnotationAwareTransactionalTests.isRollback(AbstractAnnotationAwareTransactionalTests.java:
257)
[testng] at
org.springframework.test.AbstractTransactionalSpringContextTests.onSetUp(AbstractTransactionalSpringContextTests.java:
207)
[testng] at
org.springframework.test.AbstractSingleSpringContextTests.setUp(AbstractSingleSpringContextTests.java:
103)
[testng] at
com.grey.npas.dao.survey.SurveyDAOTest.launchSetup(SurveyDAOTest.java:
73)
[testng] ... Removed 19 stack frames
[testng] SKIPPED CONFIGURATION: @AfterTest launchTearDown


here is my code,

// $Id$
//
public class SurveyDAOTest extends AbstractJpaTests{

private SurveyDAO surveyDAO;

@Test( testName="TestName")
public void getSurvey() throws Exception{
System.out.println("**************** Is Entity Manager SET ???
***********");
System.out.println(surveyDAO);
String call = surveyDAO.doNothing();
System.out.println("************ call *********"+call);
}
public void setSurveyDAO(SurveyDAO surveyDAO){
this.surveyDAO = surveyDAO;
}

@BeforeTest
public void launchSetup() throws Exception {
setUp();

}

@AfterTest
public void launchTearDown() throws Exception {
tearDown();
}

protected String[] getConfigLocations() {
return new String[]{"classpath:config\\applicationContext-
test.xml"};
}
}

ApplicationContext

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
default-autowire="byName">

<bean id="entityManagerFactory"

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean

class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true" />
<property name="generateDdl" value="true" />
<property name="databasePlatform"
value="org.hibernate.dialect.MySQL5Dialect" />
</bean>
</property>
</bean>

<bean id="dataSource"

class="org.springframework.jdbc.datasource.DriverManagerDataSource"
destroy-method="close">
<property name="driverClassName"
value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/npas" />
<property name="username" value="root" />
<property name="password" value="liferay" />
</bean>

<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager" />

<tx:annotation-driven />
<bean

class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /
>
<bean id="surveyDAO" class="com.grey.npas.dao.survey.SurveyDAOImpl" >
</bean>
</beans>

I read somewhere online that in newer version of spring-test.jar it is
not allowing testNG to set method name.

IS it BUG ??????


Thank You in advance for you time to reading this thread. Solutions
will be appreciated.



Alexandru Popescu ☀

unread,
Mar 20, 2008, 4:28:51 PM3/20/08
to testng...@googlegroups.com

By looking at the stack traces I would say that this is a problem
either in the spring-test support or JUnit.

./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator

dhavaly2k

unread,
Mar 20, 2008, 7:58:08 PM3/20/08
to testng-users
I found somewhere this is bug in spring.

Here is post i found somewhere.

Spring 2.5's Support for TestNG

Is in the toilet now. On my continuing desert odyssey to figure out
how I can write a test that puts some info in the db before running
the tests, then removes it, I ventured into 2.5, after finding this
which I thought was a eureka moment as I finally found someone who was
using JPA to do their setup (figures too it's Thomas Risberg). Problem
is the AbstractJpaTests class is in the new spring-test jar in 2.5,
and after pulling that in, I followed the Risberg example and
overloaded onSetupInTransaction(), but that never gets called. After
downloading the source, my suspicions were confirmed: there is no
annotation to trigger the call to setup. Little further investigation
revealed that there is now a testng package, but of course, the JPA
tests don't extend those classes (and apparently, they have changed
their TestNG strategy to use BeforeGroup/AfterGroup). Meanwhile,
Spring now offers a bunch of test functionality that overlaps TestNG,
e.g. @ExpectedExcption (though their's takes one class). It seems that
the thinking in the Spring camp was that the
AbstractTransactionalDataSourceTest was the last word on needing to
provide db setup services. There are a plethora of examples out there
that in fact demonstrate the inadequacy of this approach, like this
one . I think I would go bag groceries before I would resort to
jamming insert statements into a test setup. Really nice from a
support/refactoring point of view especially.

Updates - More light here (even if you use the TestNG classes, the
setup sequence is wrong and already being arbitrated in their defect
tracker….)

BUT MY QUESTION IS HOW CAN I SOLVE IT???
ONE OF THE WAY IS I HAVE TO OVERRIDE GETNAME METHOD BUT I AM LOOKING
FOR BETTER ONE.

If you include following method in your Class then it will work good.
name must be equal to method name. I am looking for better solution.

@Override
public String getName(){
return "getSurvey";
}

Thank You,

On Mar 20, 4:28 pm, "Alexandru Popescu ☀"
<the.mindstorm.mailingl...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages