junit

Running junit tests in parallel ?

I'm using junit 4.4 and maven and I have a large number of long-running integration tests. When it comes to parallellizing test suites there are a few solutions that allow me to run each test method in a single test-class in parallel. But all of these require that I change the tests in one way or another. I really think it would be a m...

Unable to run junit tests in Eclipse

I and my colleagues have an intermittent problem running junit tests or tomcat from within Eclipse. Sometimes the tests will run. Sometimes they will not. There appears to be no pattern and we are not in sync. IE mine might run and others will fail. Stopping/starting Eclipse can resolve the issue (sometimes). Pulling out the network ca...

No Such Method Error when creating JUnit test

I've tried figuring out this problem for the last 2 days with no luck. I'm simply trying to create an annotation based JUnit test using the spring framework along with hibernate. My IDE is netbeans 6.5 and I'm using hibernate 3, spring 2.5.5 and JUnit 4.4. Here's the error I'm getting: Testcase: testFindContacts(com.mycontacts.data.d...

Using PowerMock or How much do you let your tests affect your design?

I've been a fan of EasyMock for many years now, and thanks to SO I came across references to PowerMock and it's ability to mock Constructors and static methods, both of which cause problems when retrofitting tests to a legacy codebase. Obviously one of the huge benefits of unit testing (and TDD) is the way it leads to (forces?) a much...

How should you write junit test cases for multiple implementation of the same interface?

Before asking question, let me explain the current setup: I have an service interface, say Service, and one implementation, say ServiceImpl. This ServiceImpl uses some other services. All the services are loaded as bean by spring. Now, I want to write junit test cases for the ServiceImpl. For the same, I use the applicationContext to g...

Unable to get hudson to parse JUnit test output XML

EDIT: This issue has been fixed by google in gtest 1.4.0; see the original bug report for more information. I've recently switched to gtest for my C++ testing framework, and one great feature of it which I am presently unable to use is the ability to generate JUnit-style XML test reports, which could then be read in by our hudson build ...

Best practicies for JUnit and RMI Apps, RMI Registry

I'm looking to write a set of system integration tests for an RMI client application. I'd like to start the RMI server in JUnit 3.8.2 and then run those tests. Has anyone done this? I'm using something like this in a pojo with main: import java.rmi.registry.*; .... //setup try { java.rmi.registry.LocateReg...

junit & java : testing non-public methods

Hi all, I'm new to doing serious unit testing as well as junit. JUnit will only test those methods in my class that are public. How do I do junit testing on the ones that are not (i.e., private, protected)? I can test them by not using junit, but I was wondering what the junit standard method was. Please let me know. Thanks, jbu ...

Spec. for JUnit XML Output

Where can I find the specification of JUnit's XML output. My goal is to write a UnitTest++ XML reporter which produced JUnit like output. See: "Unable to get hudson to parse JUnit test output XML" and "http://stackoverflow.com/questions/411218/hudson-c-and-unittest" ...

Junit4 Test Suites

How do I create test suites with Junit4? All the documentation I've seen doesn't seem to be working for me? And if I use the eclipse wizard it doesn't give me an option to select any of the test classes I created? An up-to-date easy to digest documentation/tutorial link would be most welcome :) Thanks, Adam ...

Configuring ant to run unit tests. Where should libraries be? How should classpath be configured? avoiding ZipException [Fixed]

Hi All, I'm trying to run my junit tests using ant. The tests are kicked off using a JUnit 4 test suite. If I run this direct from Eclipse the tests complete without error. However if I run it from ant then many of the tests fail with this error repeated over and over until the junit task crashes. [junit] java.util.zip.ZipExcept...

How to get Junit 4 to ignore a Base Test Class?

I have a base class for many tests that has some helper methods they all need. It does not by itself have any tests on it, but JUnit (in eclipse) is invoking the test runner on it and complaining that there are no methods to test. How can I make it ignore this class? I know I could add a dummyTest method that would solve the problem, ...

How to handle large strings in unit tests?

Hi! I've got a question about testing methods working on strings. Everytime, I write a new test on a method that has a string as a parameter. Now, some issues come up: How to include a test string with \n, \r, \t, umlauts etc? How to set the encoding? Should I use external files that are opened by a FileInputStream? (too much overhea...

JUnit: Making sure failures in the test method are shown before failures in @After methods

I have designed a small test case class that is designed to make mocking easier (in this case, with JUnit 4 and EasyMock). Part of this is verifying the mocks after the test has finished, so the mocks are verified in a method annotated with @After. However, if there is a failure in the test method itself, which causes the test not to be...

Comparing text files w/ Junit

I am comparing text files in junit using: public static void assertReaders(BufferedReader expected, BufferedReader actual) throws IOException { String line; while ((line = expected.readLine()) != null) { assertEquals(line, actual.readLine()); } assertNull("Actual had more lines then the expected.", ac...

Set working directory in <junit> Ant task

Hi, My Ant build includes a junit task that runs some tests. In order for the tests to work, the value of the property that specifies the current working directory (user.dir) must be changed, but I am unsure how to achieve this. The task in question currently looks like this: <junit printsummary="withOutAndErr" fork="true" haltonfailu...

Get name of currently executing test in JUnit 4

In JUnit 3, I could get the name of the currently running test like this: public class MyTest extends TestCase { public void testSomething() { System.out.println("Current test is " + getName()); ... } } which would print "Current test is testSomething". Is there any out-of-the-box or simple way to do this...

JUnit Exception Catching

I am writing a few test cases that depend on the database being available, so on the @Before and @After I open and close the session (Hibernate), as well as start and finish the transaction. Now in the process of development sometimes I get exceptions in the test cases, so the @After is never called and I can't clean up (or rollback the...

JUnit produces strange AssertionFailedError

I am currently using JUnit 4.4 and Java 1.6.x. And after a recent code fix, we started getting this AssertionFailedError in my JUnit tests on the method: UtilityTest.testParseDate(4t): Mon Jan 15 09:26:07 PST 2001 expected: "Mon Jan 15 09:26:07 PST 2001" but was: "Mon Jan 15 09:26:07 PST 2001" junit.framework.AssertionFailedError: Util...

How perform Junit tests with Struts - Ibatis

Hello everyone, im using Struts 1.2.x and Ibatis 2.x version for development, so i finish yesterday and now i want to perform test this is my first time trying to work with JUnit, I already make test but in JavaApp not running on server, so how can I simulate or generate mocks with server behavior, and wich mocks are recommended for Stru...