junit

Testing against Java EE 6 API

I write an addition to JAX-RS and included the Java EE 6 API as a Maven dependency. <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> Then I have a little test case: @Test public void testIsWriteable() { class SpecialViewable...

What's the difference between failure and error in JUnit?

I'm running JUnit tests on a large code base, and I've been realizing that sometimes I get "Errors" while other times I get "Failures". What's the difference? ...

Can load .properties file in eclipse PDE fragment project

I have created an eclipse plugin project and a corresponding fragment project which I use for junit tests. In the fragment I specify the plugin project as the "Host plugin". Further I specify the following on the build.properties pane: source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ my.prope...

How to output additional debugging information using Eclipse and Android JUnit

I am developing a simple android application using eclipse. I wrote a JUnit TestCase for a class I wrote. One particular test compares two 2d arrays so see if they are equal. If they are not equal the test fails. When the test fails I would like to print out the contents of the offending array to see what went wrong. I have tried Sys...

How can I simplify testing of side-effect free methods in Java?

Functions (side-effect free ones) are such a fundamental building block, but I don't know of a satisfying way of testing them in Java. I'm looking for pointers to tricks that make testing them easier. Here's an example of what I want: public void setUp() { myObj = new MyObject(...); } // This is sooo 2009 and not what I want to wr...

JUnit vs TestNG

For one reason or another I've been asked to write a short summary to what the advantages and disadvantages of both JUnit and TestNG are compared to each other. Ideally I want to suggest what types of project each would be used for. I have essentially no experience with Unit Testing, so I have been reading up on each of the tools, as we...

Junit Android ActivityUnitTestCase: How do you make it use a target Application instance?

So I have a custom Application class which has global state in it custom to my application. Currently inside of my activityUnitTest the Application object does not seem to be instantiated and it causes a lot of underlying calls to fail. How do you go about telling the ActivityUnitTest to create an instance of my desired application Objec...

Extending Junit4 or test case?

Hello all, We've got a simple webservice for handling queries about our data. I'd like to make a set of asserts/case extentions that would provide high level methods for testing various aspects of the response. For instance I could write assertResultCountMinimum(int). The method would take care of building the query, executing it, and u...

Junit test methods

What are the most oftenly used test methods I should start with in order to get familiar with unit testing? There are just a lot of them, but I guess there are some like common or something. I meant Junit methods like AssertTrue(), etc. ...

Using assertArrayEquals in unit tests

My intention is to use assertArrayEquals Junit method described out there: [http://www.junit.org/apidocs/org/junit/Assert.html#assertArrayEquals(int[], int[])][1] for verification of one method in my class. But it happened Eclipse shows me the error message it can't recognize such a method. Those two imports are in place: import java.u...

Handling unit tests with a condition on the current time

I'm taking a stab at setting up unit tests for some utility classes in a project I'm working on, and one of the classes (contains licensing info) has a method that does some determination based on the current time. i.e. the license contains an expiry date, and the license string validates that date, but the actual logic to see if the li...

How can I bind a DataSource to an InitialContext for JUnit testing?

I'm trying to run JUnit tests on database "worker" classes that do a jndi lookup on an InitialContext to get a DataSource. The worker classes are usually running on a Glassfish v3 App Server which has the appropriate jdbc resources defined. The code runs just fine when deployed on the App Server but doesn't run from the JUnit testing en...

Trying to run trivial Android JUnit tests. Getting: "Test run failed: No test results" What am I missing?

I have never used JUnit before, and now I'm trying to set it up on an Android project. My project under test is fairly complex, including some JNI, but my test project, at the moment, is completely trivial. I have found many examples (that look totally different) online of how to make a test project, but it seems that no matter which o...

JBoss Arquillian integration with Apache Ant and Junit

Has anyone managed to integrate Arquillian with Ant and JUnit? If so, could you provide an example? ...

how to determine junit code coverage?

How can i determine what percentage of my methods are covered by jUnit tests? I am assuming there is a more sophisticated way then simply counting ...and one and two etc ... I specifically wonder how will such counting be handled when single method is covered by 'n' tests. please let me know and as always "thanks for reading" ...

OpenJPA, Jersey, JUnit: Using a different persistence unit for my unit tests?

Hi all. I'm building an application using OpenJPA 2.0.0, Jersey 1.3, and JUnit 4.8.1. I've set it up so I have two different persistence units defined in my persistence.xml: "default" and "unittest." Default is set up to connect to an Oracle instance, while unittest is set up to connect to a local H2DB embedded database file. I do th...

Setting Environment Variables for All JUnit Tests in Eclipse

Hello everyone! I am trying to set up some unit tests, which use the database. I would like to use a test database on the developer's computer instead of on the production database. The method I have in place now is to check an environment variable when connecting to the database, and if that variable exists to connect to the local on...

JUnit TestCase Failure

I'am running my JunitTest and it gives the following error.. not failure. Error creating bean with name 'reportDAO' defined in class path resource [LT.xml]: Cannot resolve reference to bean 'hibernateTemplate' while setting bean property 'hibernateTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException...

Running an JUnit test as Ant target

Hi, I've got a simple test case in /build directory that I'm trying to compile and run with Ant. Compilation is fine, but I can't figure out how to run this. The class is: package money; import org.junit.*; import static org.junit.Assert.*; public class MoneyTest { @Test public void testAmount() { Money m = new Money(...

How do I use a JUnit Parameterized runner with a varargs constructor?

I wrote a mockup example to illustrate this without exposing anything confidential. It's a "dummy" example which does nothing, but the problem occurs in the test initialiser. @RunWith(Parameterized.class) public class ExampleParamTest { int ordinal; List<String> strings; public ExampleParamTest(int ordinal, String... strings) { t...