junit

How to write multi-threaded unit tests?

I'd like to know if there are some unit testing frameworks which are capable of writing multi-threaded tests easily? I would imagine something like: invoke a special test method by n threads at the same time for m times. After all test threads finished, an assertion method where some constraints should be validated would be invoked. My...

How do I Dynamically create a Test Suite in JUnit 4?

I would like to create a junit test suite using JUnit 4 where the names of the test classes to be included are not known until the test suite is run. In JUnit 3 I could do this: public final class MasterTester extends TestCase { /** * Used by junit to specify what TestCases to run. * * @return a suite containing what TestCa...

Generate Junit test results from a build.xml in a android project

Hi. i am trying to run and publish my junit tests in html using a build.xml file calling the junit target but it doesnt seem to work. here is how my build.xml looks like: <target name="Unity Agent SDK Test "> <mkdir dir="${junit.output.dir}" /> <echo message="making directory" /> <junit fork="yes" printsummary="yes"> ...

How to test an anonymous inner class that calls a private method

We have a bunch of classes that listen for events from the server and then respond to them. For example: class EventManager { private Set<Event> cache = new HashSet<Event>(); private EventListener eventListener = new EventListener() { void onEvent(Event e) { if (e instanceof MyEvent || e instanceof YourEvent) ...

Inject sql data in a Spring junit test with an annotation

Hi, im using Junit with spring-test and i would like to have a classic transactionnal test with this annotation: @Injectdata("classpath:src/test/mydata.sql") @Test public void myTest throws Exception{ ... } This data will be injected with the jdbcspring template in the same transaction & those datas will be available for only this test...

Android JUnit has no output in Eclipse JUnit view

I followed the online directions for building HelloAndroid and HelloAndroidTest in Eclipse. The test runs, the logcat shows the correct results going to stdout, but the JUnit testrunner window in Eclipse is silent - nothing. I am running the test on a Nexus One with Android 2.2 installed via OTA. I've been unable to find any mention of ...

JUnit + Maven + Eclipse: Why @BeforeClass does not work?

I am using JUnit 4, Maven 2 and latest Eclipse. Problem is simple: I would like to perform some setup (connecting to a database) before my tests are executed. I tried @BeforeClass in many different locations but Eclipse and Maven are ignoring this. Any help on accomplishing this initial setup? Thanks! public abstract class BaseTestCas...

Testing Android ContentProvider that accesses the Internet

I've written my own Android ContentProvider for accessing certain Internet resources. I'm trying to write some unit tests, but I do not want those tests to actually access the Internet. Behind the scenes, my code is using the DefaultHttpClient class to access the web. Basically, I'd like to know how I can use the ProviderTestCase2 cla...

How to use JUnit tests with Spring Roo? (Problems with EntityManager)

I'm trying to write a JUnit test for a Spring Roo project. If my test requires use of the entity classes, I get the following Exception: java.lang.IllegalStateException: Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?) The Spring Aspects JAR looks to be configured correctly....

Using Junit 4's Timeout @Rule with Spring's AbstractTransactionalJUnit4SpringContextTests

When i use Junit's org.junit.rules.Timeout with spring's base class AbstractTransactionalJUnit4SpringContextTests, i get this exception: org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress The log ou...

how to test row locked exception in junit

Is there a way in junit to test rowlocked exception? ...

Eclipse - BEA Workshop issues Help!

My eclipse workshop keep terminating on me while in the middle of test run or just navigation. Below is the error property i keep getting. Can anyone help stop this nightmare. Thanks ===== JVM terminated. Exit code=1 C:/bea/jdk150_11/jre/bin/javaw.exe -Xms384m -Xmx768m -XX:MaxPermSize=256m -Dweblogic.home=C:/bea/wlserver_10.0 -Dosgi.ins...

Where do you keep your Stubs?

One of the JUnit best practices is : same package, separate directories. I am wondering what is the equivalent for Mock classes ? Do you keep them in the same package as classes they are supposed to mock, but in the test directory ? or elsewhere ? ...

Eclipse - default to JUnit 3

How can I tell my modern Eclipse (Galileo, Helios) that all unit tests in my workspace (or anywhere) are written in JUnit 3 and so I would like them to be run with this older JUnit version? I am talking about project/workspace/system default. Not a single specific test suite. I need it to use JUnit 3 by default for all these tiny 10-ca...

Play! + Siena + GAE + JUnit

I am trying to get some basic unit tests up and running on the Play! framework using the Siena persistence library with GAE as the intended deployment target. I have the project configured properly and can deploy the app to GAE. I created a basic domain object: public class User extends Model { @Id(Generator.AUTO_INCREMENT) pu...

How should I test private methods in java?

Possible Duplicate: Whats the best way of unit testing private methods? I am a beginner programmer, and I don't know how to write an application that will be well structured for unit testing. I want to write applications with the ability to afterwards add effective unit tests. The problem is with private methods - they can't ...

Does reflection breaks the idea of private methods, because private methods can be access outside of the class?

Hi, Does reflection breaks the idea of private methods, because private methods can be access outside of the class? (Maybe I dont understand the meaning of reflection or miss something else, please write) http://en.wikipedia.org/wiki/Reflection_%28computer_science%29 Edit: If relection breaks the idea of private methods - does we use p...

How to do unit test for Exceptions ?

As you know, exception is thrown at the condition of abnormal scenarios. So how to analog these exceptions? I feel it is challenge. For such code snippets: public String getServerName() { try { InetAddress addr = InetAddress.getLocalHost(); String hostname = addr.getHostName(); return hostname; } c...

Support for POSTing XML in HttpUnit?

Does HttpUnit support getting a response from an HTTP POST with an xml argument? Edit If you want to send a post request, you might instantiate a PostMethodWebRequest object. WebRequest request = new PostMethodWebRequest("http://example.com/thing/create"); And if you want to set parameters for that request, I think what you would do...

How can a test 'dirty' a spring application context?

The spring framework documentation states: In the unlikely case that a test may 'dirty' the application context, requiring reloading - for example, by changing a bean definition or the state of an application object - Spring's testing support provides mechanisms to cause the test fixture to reload the configurations and...