Mã này sử dụng Spring 3.1 và junit4 và spring-test 3.1. Tôi muốn chuyển mã này bằng cách sử dụng và tải junit3.8.x. Điều này là do một hệ thống xây dựng kế thừa. Tôi có thể làm cái này như thế nào? Hầu hết tài liệu trực tuyến cho mùa xuân được tập trung xung quanh cách tiếp cận bên dưới. Tôi cần để có thể 'tải các lớp học mùa xuân'. Trong trường hợp này, tôi có một tệp XML, rest-servlet.xml
và các lớp 'dịch vụ' được chú thích. Tôi muốn có thể tải tập tin cấu hình spring-servlet spring đó và thiết lập spring trước mỗi test.Làm thế nào tôi có thể biến thử nghiệm junit4 'mùa xuân 3.1' theo định hướng này với SpringJUnit4ClassRunner thành thử nghiệm dựa trên junit3.8 theo mùa xuân?
<?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:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.ca.services.rest.*,com.ca.services.test.*" />
<mvc:annotation-driven />
</beans>
TestActivityLog:
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.ca.services.rest.activity.services.ActivityDaoRepository;
import com.ca.services.rest.activity.services.ActivityService;
import com.ca.services.rest.activity.services.impl.ActivityServiceImpl;
import com.ca.services.test.mock.MockActivityDaoRepository;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"file:**/WEB-INF/rest-servlet.xml"})
public class TestActivityLog {
@Autowired
@Qualifier("mockActivityDaoRepository")
private MockActivityDaoRepository repository;
@Autowired
private ApplicationContext applicationContext;
@Autowired
public TestActivityLog() {
super();
}
@Before
public void setup() throws Exception {
}
@Test
public void testOne() {
Assert.assertEquals("abc", "abc");
}
public void testService2() {
final ActivityDaoRepository repo = repository;
final String chk1 = "[POL.ActivityAPI:as1.0.0]";
final String chk2 = String.valueOf(repo.getVersion());
Assert.assertEquals(chk1, chk2);
}
public void testService3() {
final ActivityService service = new ActivityServiceImpl(repository);
}
}
Điều đó sẽ hiệu quả, tôi nghĩ có khoảng 3,8 lớp trong mùa xuân. –