junit

Is there anyway to bring web @Context into JUnit (CXF+Spring)

I am trying to create unit test environment to test RESTFul services (cfx+spring) in my dev environemnt. To test RESTFul Services, I require @Context within JUnit test cases. @Context should contain HttpRequest, HttpSession, ServletContext, ServletConfig and all other webserver related information. I have setup the JUnit for the above, ...

Java: Can't implement runnable on a test case: void run() collides

So I have a test case that I want to make into a thread. I cannot extend Thread nor can I implement runnable since TestCase already has a method void run(). The compilation error I am getting is Error(62,17): method run() in class com.util.SeleneseTestCase cannot override method run() in class junit.framework.TestCase with different retu...

Debugging maven junit tests with filtered resources?

We are using filtered testResources in JUnit-tests that are usually executed by the maven surefire plugin. That is, the pom contains a section <build> <testResources> <testResource> <directory>src/test/resources</directory> <filtering>true</filtering> </testResource> </testResources> ... How c...

Spring/Hibernate/Junit example of testing DAO against HSQLDB

Hi guys, I'm working on trying to implement a JUnit test to check the functionality of a DAO. (The DAO will create/read a basic object/table relationship). The trouble I'm having is the persistence of the DAO (for the non-test code) is being completed through an in-house solution using Spring/Hibernate, which eliminates the usual *.hb...

How to create TestContext for Spring Test?

Newcomer to Spring here, so pardon me if this is a stupid question. I have a relatively small Java library that implements a few dozen beans (no database or GUI). I have created a Spring Bean configuration file that other Java projects use to inject my beans into their stuff. I am now for the first time trying to use Spring Test to inj...

Configure JNDI names with Open EJB

I'm trying to (unit) test my EJB class without having to startup my websphere environment. Now I'm using Open EJB, but there are some issues with resolving the JNDI Names for other EJBs that are used within my EJB... and there is no way for me to inject mocked classes from my test right now. Getting the InitialContext final Properties ...

Classpath trouble using JUnit with both Eclipse and Maven

In a JUnit test I'm using this code to load in a test-specific config file: InputStream configFile = getClass().getResourceAsStream("config.xml"); When I run the test through eclipse, it requires the xml file to be in the same directory as the test file. When I build the project with maven, it requires the xml to be in src/test/resourc...

Spring Test / JUnit problem - unable to load application context

I am using Spring for the first time and must be doing something wrong. I have a project with several Bean implementations and now I am trying to create a test class with Spring Test and JUnit. I am trying to use Spring Test to inject a customized bean into the test class. Here is my test-applicationContext.xml: <?xml version="1.0" e...

Ehcache hangs in test

I am in the process of rewriting a bottle neck in the code of the project I am on, and in doing so I am creating a top level item that contains a self populating Ehcache. I am attempting to write a test to make sure that the basic call chain is established, but when the test executes it hands when retrieving the item from the cache. Her...

JUnit parallel to Rails Fixtures?

My team has a set of POJO's that we build up to pass into our code and test various functions. For example we have an Address class which contains address information. It doesn't make sense to constantly rebuild this class every time we have to whack an address onto an object to test something. I am thinking that something like Rails'...

Reflection in unit tests for checking code coverage

Here's the scenario. I have VO (Value Objects) or DTO objects that are just containers for data. When I take those and split them apart for saving into a DB that (for lots of reasons) doesn't map to the VO's elegantly, I want to test to see if each field is successfully being created in the database and successfully read back in to reb...

Emma - Block Coverage vs Line Coverage

I have a strange scenario... while doing a EMMA coverage for UT, I get the total block coverage size more than line coverage size. For block coverage, the total size is some 50,000 while the line coverage is out of 18,000. I get (block-coverage-value) / 50,000 and (line-coverage-value) / 18,000 in the report. Is it possible? How can t...

Unit-test framework for bean comparison

Is there any good framework for comparing whole objects? now i do assertEquals("[email protected]", obj.email); assertEquals("5", obj.shop); if bad email is returned i never get to know if it had the right shop, i would like to get a list of incorrect fields. ...

JUnit - assertSame

Can someone tell me why assertSame() do fail when I use values > 127? import static org.junit.Assert.*; ... @Test public void StationTest1() { .. assertSame(4, 4); // OK assertSame(10, 10); // OK assertSame(100, 100); // OK assertSame(...

JUnit - Testing a method that in turn invokes a few more methods

Hi, This is my doubt on what we regard as a "unit" while unit-testing. say I have a method like this, public String myBigMethod() { String resultOne = moduleOneObject.someOperation(); String resultTwo = moduleTwoObject.someOtherOperation(resultOne); return resultTwo; } ( I have unit-tests wri...

Running each JUnit test in a separate JVM in Eclipse?

I have a project with nearly 500 individual tests in around 200 test classes. Some of these tests don't do a great job of tearing down their own state after they're finished, and in Eclipse this results in some tests failing. The tests all pass when running the test suite from the command line via Ant. Can I enable 'test isolation' some...

Netbeans Profile JUnit 4 problem

I have a unit test that takes 200 sec to run. I am trying to use NetBeans profiler to speed it up. But the profiler doesn't run the unit test. It just creates an object of the test and exits. Doesn't run the actual test methods or @Before / @After methods. This is a maven project with surefire and junit 4. And partial output is bel...

How to execute ant using java and captured the output?

Hi, I have an ant build file that contains JUnit test suite that I would like to execute. Currently I just right click and run the build file from Eclipse. I want to write a java code that can execute the ant build file automatically. So I just run the code and ant will be executed. Second is I want to capture the test result. Current...

Include Unit tests in the same package as the source code in Java

I'm getting back into Java after a long stint in the Ruby world and I've got a question about JUnit tests and the source I'm testing. If I've got a package of graphics code for my company, lets call it com.example.graphics, should I include my tests in that package too or should they be included in a seperate package, like com.example.g...

Can I write a test without any assert in it ?

Hi, I'd like to know if it is "ok" to write a test without any "assert" in it. So the test would fail only when an exception / error has occured. Eg: like a test which has a simple select query, to ensure that the database configuration is right. So when I change some db-configuration, I re-run this test and check if the configuration ...