当前页面: 开发资料首页 → J2EE 专题 → [请教]spring的单元测试,在eclipse中正常,但是在ant中报错。100分送上
[请教]spring的单元测试,在eclipse中正常,但是在ant中报错。100分送上
摘要: [请教]spring的单元测试,在eclipse中正常,但是在ant中报错。100分送上
使用继承自spring-mock中的AbstractTransactionalDataSourceSpringContextTests类的测试类,代码简化后如下:
public class CategoryServiceTest extends
AbstractTransactionalDataSourceSpringContextTests {
private CategoryService categoryService;
public void setCategoryService(CategoryService categoryService) {
this.categoryService = categoryService;
}
public void testAdd() {
// do some test
}
}
在eclipse中运行正常,一个绿条。但是在ant中运行就会报错,ant代码如下:
name="test"
depends="init"
description="Run unit tests">
fork="yes"
haltonfailure="yes">
<formatter
usefile="false" />
<formatter type="xml" />
dir="${build.dir}"
includes="**/*Test.class">
ant运行结果如下:
[junit] Testsuite: test.service.CategoryServiceTest
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0.461 sec
[junit] ------------- Standard Error -----------------
[junit] 2006-6-18 2:35:18 org.springframework.test.AbstractSpringContextTests loadContextLocations
[junit] 信息: Loading config for: classpath*:conf/spring/*.xml
[junit] 2006-6-18 2:35:18 org.springframework.core.CollectionFactory
[junit] 信息: JDK 1.4+ collections available
[junit] 2006-6-18 2:35:18 org.springframework.core.CollectionFactory
[junit] 信息: Commons Collections 3.x available
[junit] 2006-6-18 2:35:18 org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
[junit] 信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9627532]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy
[junit] 2006-6-18 2:35:18 org.springframework.context.support.AbstractApplicationContext refresh
[junit] 信息: No beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=9627532]
[junit] 2006-6-18 2:35:18 org.springframework.context.support.AbstractApplicationContext initMessageSource
[junit] 信息: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@13c5982]
[junit] 2006-6-18 2:35:18 org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
[junit] 信息: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@c2ea3f]
[junit] 2006-6-18 2:35:18 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
[junit] 信息: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans []; root of BeanFactory hierarchy]
[junit] ------------- ---------------- ---------------
[junit] Testcase: testAdd took 0.401 sec
[junit] Caused an ERROR
[junit] Error creating bean with name 'test.service.CategoryServiceTest': Unsatisfied dependency expressed through bean property 'categoryService': Set this property value or disable dependency checking for this bean.
[junit] org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'test.service.CategoryServiceTest': Unsatisfied dependency expressed through bean property 'categoryService': Set this property value or disable dependency checking for this bean.
[junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.checkDependencies(AbstractAutowireCapableBeanFactory.java:730)
[junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:571)
[junit] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:234)
[junit] at org.springframework.test.AbstractDependencyInjectionSpringContextTests.setUp(AbstractDependencyInjectionSpringContextTests.java:201)
BUILD FAILED
头都想破了,也没想通为什么。在eclipse中直接运行这个测试是好的啊,为什么ant就不行呢
请各位大侠指点一二。
原因已经查明,,,低级错误,原来ant中的其它错误把spring的配置文件删除了。
郁闷的是,报的错(依赖不对)与实际的错误(配置文件没找到)查的实在有点远。
100分送给接分的朋友中,昵称最长的一个(不含签名) :)
哎
接分
呵呵,接分吧.我刚在看Ant,不过从你这也学了东西
接分
都是粗心造成的,以后注意哦
拿到分了!
:)