junit

Putting Spring integration tests in different classes and packages

I am using AbstractTransactionalSpringContextTests to run spring integrations tests. The spring context is loaded just once and then all the tests are run. How do I do the same if I want my tests to be in many classes and packages. Of course, the spring context should be loaded just once for all my tests (in all classes and packages), a...

How can I improve my junit tests

Right my junit tests look like a long story: I create 4 users I delete 1 user I try to login with the deleted user and make sure it fails I login with one of the 3 remaining user and verify I can login I send a message from one user to the other and verify that it appears in the outbox of the sender and in the inbox of the receiver. I...

Forcing FileNotFoundException

I'm writing a test for a piece of code that has an IOException catch in it that I'm trying to cover. The try/catch looks something like this: try { oos = new ObjectOutputStream(new FileOutputStream(cacheFileName)); } catch (IOException e) { LOGGER.error("Bad news!", e); } finally { The easiest way seems to make FileOutputStrea...

Java mock webserver

I would like to create a unit test using a mock web server. Is there a web server written in java which can be easily started and stopped from a junit test case? ...

How can create a Junit4 Suite with Groovy?

I have @RunWith(Suite.class) @Suite.SuiteClasses( [ First.class,Second.class ]) public class MySuite{ } But eclipse doesn't give me a "Run As Junit4 Test". All the individual test classes work fine with GUnit, the groovy unit test runner built into eclipse. Any thoughts? ...

Running JUnit tests with Embedded Jboss

Hi I need to run junit tests for classes using ejb3 beans. In our case setting up jboss just for this purpose is not an option and therefore we need an alternative way to simulate the ejb communication. I've read that this should be possible with Embedded Jboss's EJB3StandaloneBootstrapper, but the problem is that I cannot get it to wor...

How do you customize exception handling behavior in JUnit 3?

I want to implement exception checking (like in JUnit 4) using JUnit 3. For example, I would like to be able to write tests like this: public void testMyExceptionThrown() throws Exception { shouldThrow(MyException.class); doSomethingThatMightThrowMyException(); } This should succeed if and only if a MyException is thrown. Th...

How to use Junit to test asynchronous processes

How do you test methods that fire asynchronous processes with Junit? I don't know how to make my test wait for the process to end (it is not exactly a unit test, it is more like an integration test as it involves several classes and not just one) ...

Automatically add properties when running JUnit in Eclipse

In order to run my unit tests on my Eclipse, I need to set some properties for the VM. Thus, when I first run my JUnit test, I go in "Open Run Dialog", then in my JUnit configuration for this test, I go in "Arguments" tab and put everything I need in the "VM arguments" text area. Is there a way to automatically add a set of properties ...

Why does a junit test fail in eclipse but pass from ant?

I have a JUnit test that is checking to make sure that a customized xml serialization is working properly. The customized xml serialization is just a few custom converters for Xstream. The deserializers work, but for some reason in Eclipse 3.x, JUnit fails the serialization. In Ant on the command line, it works just fine. It also wor...

Running "pure" JUnit 4 tests using ant

We have migrated to both JUnit 4 and ant 1.7 The tests runs fine in eclipse, but the annotations are ignored when running the tests using ant. According to ant's junit task http://ant.apache.org/manual/OptionalTasks/junit.html%5D">documentation. It also works with JUnit 4.0, including "pure" JUnit 4 tests using only annotations and...

Running a single junit test in Eclipse

If I have a test suite with multiple tests, when I try to run a single unit test, either from the context menu of the code editor, or from the JUnit view, it seems to insist on always running the entire suite, rather than the single test. Is there a way to disable to change this behavior so that I can ask to to run that, and only that, t...

Change test name of parameterized tests?

Is there a way to set my own custom test case name when using Parameterized tests in Junit4? I'd like to change the default "[Test class].runTest[n]" to something meaningful... ...

Selenium fails to kill browser when test fails

How do I setUp selenium to kill the test browser page on occasions where test fails. Currently, when running selenium test cases and a test fails, the browser page stays open and that causes problems when large number of tests is failing. Interestingly enough, it isnt the case when the test passes. Any suggestion?? ...

What is the "right" way to test the output of Java methods?

In Python, I often have tests which look something like this: tests = [ (2, 4), (3, 9), (10, 100), ] for (input, expected_output) in tests: assert f(input) == expected_output What is the "right" way to write tests like this (where a set of test cases is specified, then a loop runs each of them) in Java with JUnit? Tha...

Can selenium handle autocomplete?

I have a test case that requires typing in a partial value into an ajax based textfield and verifying the list has the expected content. If it does, select the content. Any idea how to make this work? ...

Is there a selenium API call to check if somethingIsSelected in a MultiSelectField??

I am aware that there is a selenium API (isSomethingSelected) used to see if a value is selected in single-select dropdown. Is there an equivalent for multiselect? ...

Can you or do you write Junit style unit tests without expliciting using 'assertEquals', exceptions fail test

I noticed some unit tests, like in the spring framework where you setup the object and the test but don't explicitly use the assert methods. Essentially, you have an exception or not. Is this unit testing? Is this something to avoid? For example, here are some tests from the Spring framework. No assert clauses, just a test. public v...

JUnit: how to avoid "no runnable methods" in test utils classes

I have switched to JUnit4.4 from JUnit3.8. I run my tests using ant, all my tests run successfully but test utility classes fail with "No runnable methods" error. The pattern I am using is to include all classes with name *Test* under test folder. I understand that the runner can't find any method annotated with @Test attribute. But the...

JUnit tests for POJOs

I work on a project where we have to create unit tests for all of our simple beans (POJOs). Is there any point to creating a unit test for POJOs if all they consist of is getters and setters? Is it a safe assumption to assume POJOs will work about 100% of the time? Duplicate of - Should @Entity Pojos be tested? See also Is it ba...