Thursday 15 May 2014

java - Spring Test NoMethod Error -



java - Spring Test NoMethod Error -

i'm using spring run test , got weird error block me while.

writer , parser classes no attributes , using default constructors.

abstracttestcaseunit.java

@runwith(springjunit4classrunner.class) @contextconfiguration(locations = { "file:spring-configuration/unit-test-config.xml" }) public abstract class abstracttestcaseunit { @resource(name = "parser") private dataparser parser;; @resource(name = "writer") private datawriter writer; public dataparser getmessageparser() { homecoming parser; } public datawriter getdatawriter() { homecoming writer; } }

dataparsetest.java

public class dataparsertest extends abstracttestcaseunit { @test public void testparsemessagehappycase() {...} }

unit-test-config.xml

<?xml version="1.0" encoding="utf-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd "> <import resource="unit-test/environment.xml" /> <bean id="parser" class="com.datatype.dataparser" /> <bean id="writer" class="com.datatype.datawriter" />

error:

[junit] tests run: 1, failures: 0, errors: 1, skipped: 0, time elapsed: 0.013 sec [junit] [junit] testcase: initializationerror took 0.003 sec [junit] caused error [junit] org.springframework.beans.beanutils.instantiateclass(ljava/lang/class;ljava/lang/class;)ljava/lang/object; [junit] java.lang.nosuchmethoderror: org.springframework.beans.beanutils.instantiateclass(ljava/lang/class;ljava/lang/class;)ljava/lang/object; [junit] @ org.springframework.test.context.contextloaderutils.resolvecontextloader(contextloaderutils.java:87) [junit] @ org.springframework.test.context.contextloaderutils.buildmergedcontextconfiguration(contextloaderutils.java:298) [junit] @ org.springframework.test.context.testcontext.<init>(testcontext.java:100) [junit] @ org.springframework.test.context.testcontextmanager.<init>(testcontextmanager.java:117) [junit] @ org.springframework.test.context.junit4.springjunit4classrunner.createtestcontextmanager(springjunit4classrunner.java:119) [junit] @ org.springframework.test.context.junit4.springjunit4classrunner.<init>(springjunit4classrunner.java:108) [junit] @ java.lang.reflect.constructor.newinstance(constructor.java:526) [junit] @ java.lang.reflect.constructor.newinstance(constructor.java:526) [junit]

it seems mixing different (incompatible) versions of spring components. check classpath.

if using project management tool maven or gradle, ensure dependencies of project not contain spring artifacts, otherwise picked transitive dependency mechanism.

if using ide eclipse , maven, can open pom.xml pom editor , check in dependency hierarchy tab resolved dependencies. can exclude offending (often older) dependency.

java spring testing

No comments:

Post a Comment