junit

Is there a way to use a custom JUnit Test Runner when running tests in Eclipse?

I want to use JMockit's incremental test runner instead of the standard JUnit test runners from within Eclipse. Is there a way to do this? Edit Received the following answer to my email to the JMockit dev: You would need to start the JVM with a command line such as "-javaagent:jmockit.jar=incjunit4", where "incjunit4" specifie...

Testing what's written to a Java OutputStream

I am about to write junit tests for a XML parsing Java class that outputs directly to an OutputStream. For example xmlWriter.writeString("foo"); would produce something like <aTag>foo</aTag> to be written to the outputstream held inside the XmlWriter instance. The question is how to test this behaviour. One solution would of course be to...

Eclipse3.3 Junit issues running one test out of a class with more than one

Language is Java. Using JUnit4.1 jar, and jMock1.1 but still using JUnit3 style definitions. Test classes extend MockObjectTestCase (which eventually extends JUnit's TestCase). If I open a test class with more than one test, then right-click in outline view and select run, it runs that one test, then it runs all the other tests in Unro...

How is Jmock used with HttpSession and HttpServletRequest

I am new to jmock and trying to mock an HttpSession. I am getting: java.lang.AssertionError: unexpected invocation: httpServletRequest.getSession() no expectations specified: did you... - forget to start an expectation with a cardinality clause? - call a mocked method to specify the parameter of an expectation? the test method: @Tes...

What do you need to do Unit testing in Java with Eclipse?

I've recently been lifted out of the .Net world into the Java world and I miss my unit tests. Using Visual Studio I used NUnit and TestDriven.net to run my unit tests. What is a comparable system for Java Using Eclipse? I'm looking specifically for the plugins that will get me going, or a guide on how to do it. I'm aware that JUnit i...

How to retrieve maven properties inside a JUnit test?

I'm writing a test for a file parser class. The parse method receives a file name as parameter, and must open it in order to parse it ( duh ). I've writen a test file, that I put into the test/resources directory inside my project directory, and would like to pass this file to test my parse. Since this project is in CVS, and will be man...

How to set the working directory for a <junit> task to something other than the basedir?

I have an Ant script with a junit target where I want it to start up the VM with a different working directory than the basedir. How would I do this? Here's a pseudo version of my target. <target name="buildWithClassFiles"> <mkdir dir="${basedir}/UnitTest/junit-reports"/> <junit fork="true" printsummary="yes"> <classpath> <pathe...

Is there a way to separate long running (e.g. stress tests) out so they're not run by default in Maven 2?

We've had an ongoing need here that I can't figure out how to address using the stock Maven 2 tools and documentation. Some of our developers have some very long running JUnit tests (usually stress tests) that under no circumstances should be run as a regular part of the build process / nightly build. Of course we can use the surefire ...

Running Eclipse Junit Plugin tests with Junit 4.4 or newer -- why aren't tests detected?

I need to use JUnit 4.4 (or newer) in a set of eclipse plugin tests, but I've run into the following problem: Tests are not detected when running with the junit 4.4 or 4.5 bundles from springsource ([junit44] and [junit45]). The org.junit4 bundle that can be obtained with eclipse supplies junit 4.3 (as of Ganymead / Eclipse 3.4). The ...

Any disadvantages to using spring to separate tests and data?

I've been struggling coming up with a good solution to separate my testing data from unit tests (hard coded values). Until it dawned on me that I could create beans with spring and use those beans to hold my data. Are there any draw backs to coding my unit tests this way? Albeit they run a bit slower seeing as how spring has to c...

Automating unit tests (junit) for Eclipse Plugin development

I am developing Eclipse plugins, and I need to be able to automate the building and execution of the test suite for each plugin. (Using Junit) Test are working within Eclipse, and I can break the plugins into the actual plugin and a fragment plugin for unit testing as described here, here and in a couple places here. However, each of ...

Automatic JUnit on SVN checkin

I'm using IntelliJ-Idea to write Java daemons. We use JUnit to unit test our code and want to have automated runs on check-in to subversion. Are there any tools available that can automatically run unit tests and then send reports in email and to Hobbit? ...

Best way to automagically migrate tests from JUnit 3 to JUnit 4?

I have a bunch of JUnit 3 classes which extend TestCase and would like to automatically migrate them to be JUnit4 tests with annotations such as @Before, @After, @Test, etc. Any tool out there to do this in a big batch run? ...

How do I unit test jdbc code in java?

I'd like to write some unit tests for some code that connects to a database, runs one or more queries, and then processes the results. (Without actually using a database) Another developer here wrote our own DataSource, Connection, Statement, PreparedStatement, and ResultSet implementation that will return the corresponding objects base...

Longest running unit tests?

How can we find the junit tests in our suite that take the longest amount of time to run? The default output of the junitreport ant task is helpful, but our suite has thousands of tests organized into many smaller suites, so it gets tedious, and the worst offenders are always changing. We use luntbuild but ideally it would be something...

Unit tests vs integration tests with Spring

I'm working on a Spring MVC project, and I have unit tests for all of the various components in the source tree. For example, if I have a controller HomeController, which needs to have a LoginService injected into it, then in my unit test HomeControllerTest I simply instantiate the object as normal (outside of Spring) and inject the pro...

differences between 2 JUnit Assert classes

Hi, I've noticed that the JUnit framework contains 2 Assert classes (in different packages, obviously) and the methods on each appear to be very similar. Can anybody explain why this is? The classes I'm referring to are: junit.framework.Assert and org.junit.Assert. Cheers, Don ...

EMMA won't cover one of my projects

Hi, I have an issue with EMMA where it is correctly covering all my various Java projects except one. I am puzzled as to why this occurs as the ANT script appears to be correct. The following expected output is given: [echo] c:\cc_local_home\emmadata\ProjectName [instr] processing instrumentation path ... [instr] instrumentation path ...

Java: How to test methods that call System.exit()?

I've got a few methods that should call System.exit() on certain inputs. Unfortunately, testing these cases causes JUnit to terminate! Putting the method calls in a new Thread doesn't seem to help, since System.exit() terminates the JVM, not just the current thread. Are there any common patterns for dealing with this? For example, can I ...

How do I perform a Unit Test using threads?

Executive Summary: When assertion errors are thrown in the threads, the unit test doesn't die. This makes sense, since one thread shouldn't be allowed to crash another thread. The question is how do I either 1) make the whole test fail when the first of the helper threads crashes or 2) loop through and determine the state of each thread ...