junit

another java.lang.ClassNotFoundException in ant's junit task

I can't figure out why I am getting this exception from my ant build.xml file. I checked and everything is in the classpath. Why must this be so complicated?! I had trouble with Ant in the past and it seems it always is something related to the classpath. I am pointing to junit.jar using both ways: within eclipse: window->preferences->a...

creating an executable jar file with ant which includes the build.xml file

Hello, I am trying to use ant to build an application, run the application's main() method, run junit tests, and package everything in a jar file (source+build+libraries+build.xml). The classes include a runner class with a main() method entry point. The objective however is to inlcude all libraries used, like junit.jar, and the ant bu...

manipulate current time in unit testing?

Is there any way to manipulate the current time in a jUnit 4.5 test? I have the following method which I'd like to have a unit test for public String getLastWeek() { GregorianCalendar c = new GregorianCalendar(TimeZone.getTimeZone("Europe/Stockholm")); c.setFirstDayOfWeek(GregorianCalendar.MONDAY); c.add(GregorianCalendar.WEEK_OF...

Using easymock, repeated void method call

I am new to easymock. I am trying to mock a service where one of the methods is a void method that will gets called an unknown and large amount of times. How to specify that any number of calls is allowed. I know how to do it for other then void methods. Thanks, Hendrik ...

How to run concurrency unit test?

Hi, How to use junit to run concurrency test? Let's say I have a class public class MessageBoard { public synchronized void postMessage(String message) { .... } public void updateMessage(Long id, String message) { .... } } I wan to test multiple access to this postMessage concurrently. Any advice ...

Junit throw warning while still passing test

I'm working on a project at the moment that we're using junit to test, but as its still fairly early stages a lot of features aren't yet implemented, though they already have tests written for them this means these tests (obviously) always fail I was wondering if anyone knew a way to get JUnit to pass the test while displaying a warnin...

running a subset of JUnit @Test methods

We're using JUnit 4 to test: we have classes that don't are a subclass of TestCase, and they have public methods annotated with @Test. We have one file with many @Test methods. It would be nice to be able to run a subset of them via Ant from the command line, in the style of this recipe for JUnit 3: ant runtest -Dtest=MyTest -Dtests=tes...

testing hibernate parent/child relationship

hello good fellas! i use spring and hibernate for my data access layer i'll like to have some guidance about how to construct my unit testing to test if hibernate is effectively insert in the child table(parent hibernate mapping has the cascade all on the set). For what i know i shouldn't mix dao's unit testing.So supposing the i'm testi...

JPA-based JUnit Test Best Practices

This is a bit of an odd question, but it has been bothering me for a few months now. I have built a JPA-based web application using Wicket + Hibernate (built with Maven), and want to test the DAO layer directly. I created a specific src/test/resources/META-INF/persistence.xml file that I used for testing, but have been running into confl...

Java: How do I ignore certain elements when comparing XML?

I have an XML message like so: <root> <elementA>something</elementA> <elementB>something else</elementB> <elementC>yet another thing</elementC> </root> I want to compare a message of this type produced by a method under test to an expected message, but I don't care about elementA. So, I'd like the above message to be considered...

How to test void method with Junit testing tools?

I just happen to implement a method void followlink(obj page,obj link) which simply adds page and link to queue. I have unsuccessfully tried to test this kind of method. All I want is to test that in the queue contains page and link received from followlink method. My test class already extends TestCase.So what would be the best way to ...

How do I configure Eclipse to run your tests automatically ?

I read this article: Configure your IDE to run your tests automatically http://eclipse.dzone.com/videos/configure-your-ide-run-your It's pretty easy to configure Eclipse IDE to run an Ant target every time a file is saved. MyProject -> Right-click : Properties -> Builders -> New -> Ant Builder The problem is that the builder has to reb...

JUnit4 + Eclipse "An internal error occured during Launching"

Hello I'm trying to run JUnit4 test cases on Eclipse 3.4.2 but it's not even starting for me. I am sure that I properly have junit-4.7.jar in my build path and the test application. Here is a simple example that illustrates my problem package test; import org.junit.Before; import org.junit.Test; public class UTest { @Test ...

Unit-Testing PersistenceLayer (JPA/EclipseLink)

Hello Everyone I am not sure what is the correct way of testing my Database, without an prepared In-Memory-Database. I have following TestSuite for JUnit4. Ignore the JpaManager, I just need this, because the application runs as a Eclipse RCP and not in a container, nor Spring is used (yet), so I cannot inject an EntityManager-referenc...

Eclipse RCP: Using different JUnit version (4.3.1) than shipped with eclipse galileo (4.5.0)

Hallo, I have the following situation: We are developing an Eclipse RCP Application and want to switch from Eclipse 3.4 to Eclipse 3.5. Our JUnit-Tests are using JUnit 4.3.1 and we have a launch configuration to start our test suite. I think I don't need to go into more details here. The problem is: Running the tests with Eclipse 3....

verify object type with easymock

hello guys.i've just come into the world of easymock.i'll like to ask if easymock only does mock object for interfaces? So in my effort to understand i wrote a class to generate unique voucher in java.i obviously can't know which value it will generate to use in the assert stuff.So how to make sure the generated voucher is of the type l...

dbUnit data types

I'm using dBUnit and am trying to assert a row of my pre-defined FlatXmlDataSet with the actual DB dataset. The problem is the getValue for my Verification Code field returns a string when that data originates from the FlatXmlDataSet and as an Integer when its from the actual live database. This is true with any data type that isn't a St...

Spawning a separate process from within a unit test

I have some unit tests (yes, perhaps more integration-ey tests !) that I would like to spin up another jvm, and then run the test code from that "other" JVM (and wait for it to finish, collecting the results). Am interested if there is an easy/reliable way of doing that with junit (eg inherit the classpath of what is needed etc...) Any...

How can I test final and static methods of a utility project?

I'm trying to implement unit testing for aproject, it uses a legacy "utility" project that is littered with static methods and many of the classes are final or their methods are final. I'm not able to update the legacy project at all. JMock and EasyMock both choke on final methods, and I don't see a nice way to test the static calls. W...

Run all tests in a source tree, not a package

My unit tests are in a separate directory tree from my integration tests, but with the same package structure. My integration tests need external resources (e.g. a server) to be available, but my unit tests are properly independent of each other and the environment. In IntelliJ-IDEA (v7) I have defined a JUnit Run/Debug Configuration to...