【发布时间】:2015-02-24 07:37:47
【问题描述】:
我是 testng 框架的新手。从 junit 迁移到 testng 时,entityManager 返回空值。它对我来说看起来很奇怪,谁能发现我的错误。我在这里放了我的代码 sn-ps。谢谢。
实体
@Entity
@Table(name = "school")
public class School {
private Integer id;
private String schoolName;
private String address;
getters and setters here
}
测试类
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/applicationContext.xml" })
@Transactional
public class SchoolTest {
@PersistenceContext
private EntityManager entityManager;
String address,schoolName;
@BeforeClass
public void init() {
address = "chinna kadai st";
schoolName = "SVM School";
}
@Test
public void save_school() {
School school = new School();
school.setAddress(address);
school.setSchoolName(schoolName);
entityManager.persist(school);
}
}
上述代码在使用Junit时运行良好
【问题讨论】:
标签: java spring testng spring-test