junit

Cleanest way to get a File in a JUnit test case from Maven

Hi, My test code in Maven project B (which is a child of project A) has something like String filePath = "src/main/webapp"; //do something with the filePath The above test case runs fine when I run the project from child (i.e, level B) but when I run from Parent project A (i.e, doing a mvn install at parent level) this fails because o...

Parameter passed to java command while running JUnit test case

Hello, I would like to understand the meaning of the following command,with regards to JUnit: java junit.swingui.TestRunner MoneyTest The above command opens up the result of the testcase in JUnit Swing GUI. Whats the meaning of passing junit.swingui.TestRunner to the java command as a parameter ? Thank You ...

Junit (3.8.1) testing that an exception is thrown (works in unit test, fails when added to a testSuite)

I'm trying to test that I'm throwing an exception when appropriate. In my test class I have a method similar to the following: public void testParseException() { try { ClientEntitySingleton.getInstance(); fail("should have thrown exception."); } catch (RuntimeException re) { assertEquals( "<...

Compare two JSON objects in Java

I'm looking for a JSON paring library that supports comparing two JSON objects ignoring child order, specifically for unit testing JSON returning from a web service against an expected value. Do any of the major JSON libraries support this? the org.json simply does a reference comparison. ...

Run all tests in Junit 4

I want to be able to run all tests in a project programmatically. I know Eclipse has a "Run as JUnit test" configuration which somehow grabs all the tests in a project and run them. Is there any way for me to also grab the list of tests programmatically and run them? Or is there some good way to construct a test suite containing all the ...

Spring Unit/Intergration Testing setup

Hi Guru, I know I am bad, I didn't write unit testing and integration testing for my project. But know I am trying to be a good boy and I am having a hard time setting up the environment. So please help. =) I have my application context under WEB-INF/applicationContext*.xml and in my applicationContext.xml, it has a reference to a prop...

Remove Test code from java class

Hi Is there a way to strip the JUnit @Test code from my Java class. At the moment I embedded the test code in the same file as the source code to be tested (Yes I know it's bad, but it is an incentive for me to keep maintaining my test code) I'd like to strip the test methods from the code, build the binary and deploy. Thanks ...

Mock Runtime.getRuntime()?

Can anyone make any suggestions about how best to use EasyMock to expect a call to Runtime.getRuntime().exec(xxx)? I could move the call into a method in another class that implements an interface, but would rather not in an ideal world. interface RuntimeWrapper { ProcessWrapper execute(String command) throws IOException; } interf...

How can I get Hudson to be able to access JUnit?

I've got Hudson running on TOMCAT, it can build my Netbeans project using the ant build.xml, but it won't run any of my unit tests because of what I assume is a problem with the classpath: package org.junit does not exist [javac] import org.junit.After; [javac] ^ But I've got the junit-4.8.1.jar on the classpat...

ClassNotFoundException when running a JUnit test from ANT

Hi, I have the following ANT task: <target name="run-tests" depends="compile" description="run your test suite" > <junit printsummary="yes" haltonfailure="yes" showoutput="yes" > <classpath> <pathelement location="${build}/"/> <pathelement path="${java.class.path}"/> <fileset dir="lib"> <include name="**/*.jar"/> <...

How can I add source code to my dependency libraries in Maven?

For instance, I have included into my dependencies junit-addons : junit-addons. But in the maven repository there isn't any source code. And I know it exists (I have downloaded it). How can I modify the dependencies in order to use libraries from my local project instead from the maven repository (I would omit the junit-addons from the r...

Js test driver plugin for eclipse ganymade.

I have been trying with the below update links. But they are not working. Is there any latest plugin available? http://js-test-driver.googlecode.com/svn/tags/1.2 http://js-test-driver.googlecode.com/svn/update/ ...

How can I split abstract testcases in JUnit?

I have an abstract testcase "AbstractATest" for an interface "A". It has several test methods (@Test) and one abstract method: protected abstract A unit(); which provides the unit under testing. No i have multiple implementations of "A", e.g. "DefaultA", "ConcurrentA", etc. My problem: The testcase is huge (~1500 loc) and it's growin...

Does Maven surefire plugin run tests using multiple threads?

I'm wondering if the Maven surefire plugin either runs tests multi-threaded by default (and if so can the number of threads be controlled? ) or if it runs tests from the Test classes in a random order or predictable order, or if the order can dictated by some means. I haven't verified this yet (I'll do so tomorrow just looking for som...

Mockito: How to test my Service with mocking?

Hi, I'm new to mock testing. I want to test my Service method CorrectionService.CorrectPerson(Long personId). The implementation is not yet written but this it what it will do: CorrectionService will call a method of AddressDAO that will remove some of the Adress that a Person has. One Person has Many Addresses I'm not sure what the ...

JUnit: ignore @Test timeout parameter in debug mode

Is there a way to make JUnit runner ignore the timeout parameter in the @Test annotation when running the test suite in debug mode (i.e. with a debugger is attached)? I believe it cannot be done with a simple switch, but some tips on how to approach this would be appreciated as well. ...

Why is this (trivial) unit test failing?

This was taken nearly verbatim from IBM's Mastering Grails series. DateTagLib.groovy: class DateTagLib { def thisYear = { out << Calendar.getInstance().get(Calendar.YEAR) } } DateTagLibTests.groovy: class DateTagLibTests extends TagLibUnitTestCase { def dateTagLib protected void setUp() { super.setUp() ...

Is there a way to prevent Maven Test from rebuilding the database?

I've recently been asked to, effectively, sell my department on unit testing. I can't tell you how excited this makes me, but I do have one concern. We're using JUnit with Spring and Maven, and this means that each time mvn test is called, it rebuilds the database. Obviously, we can't integrate that with our production server -- it w...

Running JUNIT Test Suites in a specifc order using ANT

In the following example, 1. <target name="tests.unit"> 2. <junit> 3. <batchtest> 4. <fileset dir="tsrc"> 5. <include name="**/Test*.java"/> 6. <exclude name="**/tests/*.java"/> 7. </fileset> 8. </batchtest> 9. </junit> 10. </...

Junit 4 test suite and individual test classes

I have a JUnit 4 test suite with BeforeClass and AfterClass methods that make a setup/teardown for the following test classes. What I need is to run the test classes also by them selves, but for that I need a setup/teardown scenario (BeforeClass and AfterClass or something like that) for each test class. The thing is that when I run the...