Reputation: 13587
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.
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.
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.
How can I run a JUnit test case inside a container?
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?
Upvotes: 1
Views: 3261
Reputation: 2907
Arquillian tests allow you to run your unit test inside your container.
Doing something like :
@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.
Upvotes: 5
Reputation: 24609
You have 2 Options here:
I'd go with the second option, if you really want to do unit-tests. But your setting isn't exactly that of a Unit-Test more a kind of Integration-Test.
Upvotes: -1