今天打算吧junit整合到SSH框架中,因为之前已经整合过一次了,所以感觉应该没什么问题,主要就是导入一个org.springframework.test-3.0.5.RELEASE.jar和junit.jar,

然后直接写测试文件:

import static org.junit.Assert.assertEquals;

import java.util.List;

import javax.annotation.Resource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import cn.togo.bean.member.Account;
import cn.togo.service.member.AccountService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:beans.xml" })
public class TestDemo extends AbstractJUnit4SpringContextTests {

	@Resource
	private AccountService accountService;

	@Test
	public void test1() {
		//
		System.out.println(accountService.getAccountByUsername("test")
				.getUsername());
		// System.out.println(accountService.getAccountList());
		assertEquals("test", accountService.getAccountByUsername("test")
				.getUsername());
		// System.out.println( accountService.getCount());
		List<Account> accounts = accountService.getAllAccountList();
		for (Account account : accounts) {
			print_account(account);
		}
	}

	/**
	 * print account
	 * 
	 * @param account
	 */
	private void print_account(Account account) {
		System.out.print("name:" + account.getUsername());
		System.out.print(" id:" + account.getId());
		System.out.println();
	}
}
但是,报错了,

Unexpected exception parsing XML document from class path resource [beans.xml],

javax.xml.parsers.DocumentBuilderFactory.setAttribute(Ljava/lang/String;Ljava/lang/Object;)V

在网上搜索有人说是包冲突了,找了半天也没找到哪里冲突了,没办法 就把之前的项目拿出来跟现在的对比下,到底哪里不一样,

发现之前的项目用的是JAVA EE 6 Libraries 而现在用的是JAVA 1.4 Libraries,于是就把现在的也换成6的了,没想到居然成功了,

不过还是不太理解怎么回事。

posted on 2013-12-23 16:26  wyang0126  阅读(4042)  评论(0编辑  收藏  举报