How to test code dependent on environment variables using JUnit?

I have a piece of Java code which uses an environment variable and the behaviour of the code depends on the value of this variable. I would like to test this code with different values of the environment variable. How can I do this in JUnit? I’ve seen some ways to set environment variables in … Read more

Assert equals between 2 Lists in Junit

How can I make an equality assertion between lists in a JUnit test case? Equality should be between the content of the list. For example: List<String> numbers = Arrays.asList(“one”, “two”, “three”); List<String> numbers2 = Arrays.asList(“one”, “two”, “three”); List<String> numbers3 = Arrays.asList(“one”, “two”, “four”); // numbers should be equal to numbers2 //numbers should not be equal … Read more

Comparing arrays in JUnit assertions, concise built-in way?

Is there a concise, built-in way to do equals assertions on two like-typed arrays in JUnit? By default (at least in JUnit 4) it seems to do an instance compare on the array object itself. EG, doesn’t work: int[] expectedResult = new int[] { 116800, 116800 }; int[] result = new GraphixMask().sortedAreas(rectangles); assertEquals(expectedResult, result); Of … Read more

Class Not Found: Empty Test Suite in IntelliJ

I’m just starting the computer science program at my college, and I’m having some issues with IntelliJ. When I try to run unit tests, I get the message Process finished with exit code 1 Class not found: “edu.macalester.comp124.hw0.AreaTest”Empty test suite. I also see a message entitled “No tests were found” on the left side of … Read more

What is the JUnit XML format specification that Hudson supports?

I have Hudson as continuous integration server and I want to use option ‘Publish JUnit test result report’. But I don’t use xUnit tools for testing, instead of that i have shell scripts which run tests and return results in simple format. I am thinking to make a script which transforms these results to the … Read more

Meaning of delta or epsilon argument of assertEquals for double values

I have a question about JUnit assertEquals to test double values. Reading the API doc I can see: @Deprecated public static void assertEquals(double expected, double actual) Deprecated. Use assertEquals(double expected, double actual, double delta) instead. (Note: in older documentation versions, the delta parameter is called epsilon) What does the delta (or epsilon) parameter mean? 8 … Read more

Is Java’s assertEquals method reliable?

I know that == has some issues when comparing two Strings. It seems that String.equals() is a better approach. Well, I’m doing JUnit testing and my inclination is to use assertEquals(str1, str2). Is this a reliable way to assert two Strings contain the same content? I would use assertTrue(str1.equals(str2)), but then you don’t get the … Read more