你好,游客 登录 注册 搜索
背景:
阅读新闻

Arquillian Spring 框架扩展 1.0.0.Beta1

[日期:2012-08-18] 来源:Linux社区  作者:Linux [字体:大 中 小]

Arquillian Spring 框架扩展 1.0.0.Beta1 发布了,这也是该扩展首次发布的版本,支持客户端应用上下文注册以及 Spring 事务处理。

Arquillian 可让你在远程或者嵌入式的容器里测试业务逻辑,同时可作为一个压缩包发布到容器中,并通过客户端来进行交互测试。

Arquillian 是一个可以方便的在现有类基础性扩展测试用例,基于 JUnit 。

客户端测试:

@RunWith(Arquillian.class)
@SpringClientConfiguration("applicationContext-rest.xml")
public class ClientRestServiceTestCase {


    @Deployment(testable = false)
    @OverProtocol("Servlet 3.0")
    public static Archive createTestArchive() {
        return Deployments.createWebApplication()
                .addAsWebInfResource("mvc/web.xml", "web.xml")
                .addAsWebInfResource("service-servlet.xml");
    }


    @ArquillianResource
    private URL contextPath;


    @Autowired
    private RestTemplate restTemplate;


    @Test
    public void testGetEmployees() {


        Employee result = restTemplate.getForObject(contextPath + "/Employees/1", Employee.class);


        assertEquals("The returned employee has invalid name.", "John Smith", result.getName());
    }
}

Spring 事务测试

@RunWith(Arquillian.class)
@Transactional(manager = "txManager")
@SpringConfiguration("applicationContext.xml")
public class JpaEmployeeRepositoryTestCase {


    @Autowired
    private EmployeeRepository employeeRepository;


    @PersistenceContext
    private EntityManager entityManager;


    @Test
    public void testSave() {


        Employee employee = new Employee();
        employee.setName("Test employee");


        employeeRepository.save(employee);


        List result = entityManager.createQuery("from Employee").getResultList();


        assertEquals("Two employees were expected.", 1, result.size());
    }
}

发布详情

Component Arquillian Spring Framework Extension
Version 1.0.0.Beta1 view tag
Release date 2012-08-17
Released by Aslak Knutsen
Compiled against
  • JUnit – 4.8.1
  • Arquillian Core – 1.0.1.Final

 

Arquillian 的详细介绍:请点这里
Arquillian 的下载地址:请点这里

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款