使用JUnit进行容器内测试 [英] In-Container testing with JUnit

查看:100
本文介绍了使用JUnit进行容器内测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JUnit的新手,正在尝试在旧项目中实现它.这是一个Java EE项目.它的UI层位于Flex中,后端使用Hibernate作为带有SQL Server数据库的ORM层.它可以在Tomcat上运行.

I am new to JUnit and trying to implement it in a legacy project. It is a Java EE project. Its UI layer is in Flex and the backend has Hibernate as the ORM layer with a SQL Server Database. It runs on Tomcat.

我正在采取一些简单的步骤来自己学习JUnit并将其实现到代码库中.有一个类具有其findByFK方法.如果找到任何类,此方法将返回一个类对象数组.

I am taking baby steps to learn JUnit myself and implement it into the codebase. There is a class which has its findByFK method. This method returns an array of class objects if any are found.

该方法在Web应用程序上运行良好,但是我无法运行其JUnit测试用例.测试用例不在容器中,无法访问数据源.

The method runs fine on a web application but I can't run its JUnit test case. The test case is out of the container and doesn't have access to a datasource.

如何在容器中运行JUnit测试用例?

How can I run a JUnit test case inside a container?

我刚开始使用JUnit,并且不想让它过于复杂于集成问题.有什么方法可以解决这个问题,而不必涉及到数据源和Web服务器等问题?

I have just started with JUnit and don't want to overcomplicate it with integration issues. Is there any way to work it out without getting into stubbing the datasource and web server etc?

推荐答案

Arquillian测试允许您运行单元在您的容器中进行测试.

Arquillian tests allow you to run your unit test inside your container.

做类似的事情:

@RunWith(Arquillian.class)
public class Test {
    @Test
    public void test(){
    //your test
    }
}

将允许您将测试部署到容器中,从而使其可以访问数据库.

will allow you to deploy your test in your container, giving it access to your database.

这篇关于使用JUnit进行容器内测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆