junit

Is there a way to make Eclipse run a JUnit test mulitple times until failure?

We occasionally have bugs that appear once in every X runs. Before people check in stuff (where it is automatically JUnit'd), our devs need to pass JUnit locally via Eclipse. Is there some convenient way (built in or high-quality Plugin) to make Eclipse run the same test X times and stop if there's a failure? An alternative to just cli...

Bad form for JUnit test to throw exception?

Hi. I'm pretty new to JUnit, and I don't really know what best practices are for exceptions and exception handling. For example, let's say I'm writing tests for an IPAddress class. It has a constructor IPAddress(String addr) that will throw an InvalidIPAddressException if addr is null. As far as I can tell from googling around, the test...

JUnit tests run in eclipse return errors even though I have expected annotation

(This is a follow up question to this one.) I'm having a problem with JUnit4 tests in eclipse. I'm trying to use the @Test(expected=...) annotation to unit test exception throwing. The problem is that when I run the tests, they come back as errors instead of passing, even though I'm expecting the exceptions to be thrown. I'm using ecli...

"Forked Java VM exited abnormally" error from junit tests

I have a java junit test that passes when run alone on a development machine. We also have a hudson job which runs all the tests, invoked via ant, on a Mac OS X 10.4 node with Java 1.5. The test was passing in the hudson build until recently but now (with no related code changes) one test fails everytime with the following error: Error ...

junit testing a class with shell scripting functionality under win32

Hi, We have an API which is used in a class via an exposed interface. The API is meant for UNIX family and assumes, that every UNIX has /bin/sh. Thus when running the junit test under win32 we get: Cannot run program "/bin/sh" Is it a catch-22 situation or there is a chance to work it out? Maybe some framework other than junit exists ...

Unit test helper methods?

Hi, I have classes which prviously had massive methods so i subdivided the work of this method into 'helper' methods. These helper methods are declared private to enforce encapsulation - however I want to unit test the big public methods, is it good to unit test the helper methods too as if one of them fail the public method that calls i...

Upgrading to JUnit4 and keeping legacy JUnit 3 tests and test suites by running them together

I was surprised not to find the answer so far. If I am missing something basic I will be more than happy to know that. There is a large legacy code base that was upgraded to Java 6 (from 1.4). Large number of JUnit 3 tests are present in the code and are organized into test suite that runs successfully with JUnit 4 default runner in Ecl...

How can I run many test cases for a test method

I'm using JUnit.I have a test method to test a method and some test cases. I want to run all tes case in that test method, but I can't do that. When first test case fail, test method don't run second test case Here is my code public class ComputeServiceTest extends TestCase { //test add method public void testAdd() { ComputeServices ...

How can I invoke assertXXX manytimes using setUp() and tearDown()

I'm using JUnit. I want to invoke assertEquals() many times in a test method to test many diferent test cases but I don't want to have many test method. So I use setUp() and tearDown(). But when the first assertEquals() fail.The second assertEquals()doesn't work and setUp() method just have been invoked one time. Here is my code public...

Problem with StrutsSpringTestCase and rest-plugin

I'm able to run tests against my rest-plugin classes with StrutsSpringTestCase, but none of the parameters are set on the action. For e.g.: @Test public void testAgegateParams() throws Exception { request.setParameter("year", "2000"); request.setParameter("month", "01"); request.setParameter("day", "1"); ActionProxy pr...

Subclassing a test subject for Junit testing.

I want to test validation logic in a legacy class. The class uses a method to load effective dates from a config file. I have written a subclass of the class in question and overridden the config method so I can run my unit test against the subclass with any combination of effective dates. Is this an appropriate strategy? It strikes m...

In-MemoryDB: create schema in 'setUp()' of Unit Testing: Netbeans (6.5.1) Hibernate (3) Junit(3), HSQL (1.8)

What are the steps needed to setup an in-memory DB, build the schema automatically with Hibernate's 'hbm2ddl' tool within a Junit (3) 'setUp()' using Netbeans 6.5.1 ? I'm not using Hibernate annotations - just a mapping file. For the actual code, I want to use an on-disk database of course. [that is the Junits live a separate 'test' pac...

How can I create stub Junit tests in Eclipse?

Is there a simple way of creating stubs for Junit4 tests in Eclipse (Galileo)? ...

How do I use the Antlr generated junit file made by translating a gunit file

I am trying to make unit tests for multiple return values in Antlr. I have regular unit tests working using gunit. However, I am not too sure what to do with the junit Testgrammar.java file that is generated as per the instructions at http://www.antlr.org/wiki/display/ANTLR3/gUnit+-+Grammar+Unit+Testing I've tried running: java -cp "./...

How to use JUnit and Hibernate usefully?

I want to use JUnit to test Hibernate code such as insert, update, delete,.. method and transaction management. But I don't know how to apply unit test for Hibernate usefully and what should I test with Hibernate. How can I test DAO methods? Hope that you could give me some guides! ...

Remote JUNIT for functional testing

Hi, I would like to execute JUnit on a remote machine hosting a JVM embedded and linked to a C application through JNI. This JVM has state and access to live external resources and data which of course are not available in my build/test environment. In addition, my test/dev JVM is not linked to the C application and uses mock objects, so...

Running Selenium Tests through JUnit in Hudson

Hi, apologies for the somewhat confusing title :-) Basically, I've configured my Selenium tests to run through JUnit when I build the project through maven. If I start my Selenium Server in a command prompt and then run the maven build goal in another cmd prompt then the tests runs as expected. I figured that this process would be easy...

JUnit tests are run twice by my Ant target

I have made an Ant target that runs my JUnit 4 tests. Unfortunately all of them are executed twice! Does anyone have an idea of what I have done wrong? Here are my ant target: <target name="junit" description="Execute unit tests" depends="compile"> <delete dir="rawtestoutput"/> <delete dir="test-reports"/> <mkdir dir="rawtestoutput"/>...

JUnit 4 @BeforeClass & @AfterClass when using Suites

When using this approach below, by setting up the jUnit with Suites. We got the problem when all @BeforeClass in every Testclass will be executed before any tests starts to execute. (For each n TestClass file the @BeforeClass runs, then after they have execute, it started to execute the first MyTest.class files @Test) This will cause th...

JUnit report on Eclipse

The JUnit integration with eclipse is very nice. However, I would like a feature to be able to generate a quick report from the Unit Tests. It is possible to do so when running a headless build (and my nightly build is configured to do so), but sometimes I want to generate a report from the UI. Is there anyway to do this? command line...