ant+Junit的单元测试无法启动spring容器

发布于 2021-12-01 11:23:06 字数 1521 浏览 810 评论 0

以下junit的单元测试启动了Spring容器,在eclipse运行正常

@Test
	public void add(){
        System.out.println("Spring begin");
		ApplicationContext ac = new ClassPathXmlApplicationContext(
        "applicationContext.xml");
		final ISpiderService jdtuhu = (ISpiderService) ac.getBean("JdTuhuService");
		System.out.println(jdtuhu.toString());
		jdtuhu.work();
	}



但是用Ant 脚本调用junit时无法加载spring容器,有遇到同样问题的吗?

<?xml version="1.0" encoding="UTF-8"?>
<project name="project" default="junit">
	<property name="src.dir" location="src" />
	<property name="result.dir" location="target" />
	<property name="result.classes.dir" location="${result.dir}/classes" />
	<path id="classpath">
		<fileset dir="lib" includes="**/*.jar" />
	</path>
	
	<target name="junit">
			<junit fork="true" printsummary="yes" forkmode="once" jvm="F:Javajdk1.6binjava.exe">
				<classpath>
					<pathelement path="bin" />
					<fileset dir="lib">
						<include name="**/*.jar" />
					</fileset>
				</classpath>
				<batchtest fork="yes">
					<fileset dir="src">
						<include name="**/*JunitTest.java" />
					</fileset>
				</batchtest>
			</junit>
	</target>
	
</project>




如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文