junit

CollectionAssert in jUnit?

Is there a jUnit parallel to NUnit's CollectionAssert? ...

What is the recommended way to integrate Hamcrest into Eclipse's JUnit?

Is there a recommended way to integrate Hamcrest into the JUnit configuration in Eclipse? Currently Eclipse's JUnit comes with Hamcrest-core only. I want to edit that configuration to include Hamcrest-all. How should I do this? ...

AssertContains on strings in jUnit

Is there a nicer way to write in jUnit String x = "foo bar"; Assert.assertTrue(x.contains("foo")); ...

Hamcrest's hasItems

Why does this not compile, oh, what to do? import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.hasItems; ArrayList<Integer> actual = new ArrayList<Integer>(); ArrayList<Integer> expected = new ArrayList<Integer>(); actual.add(1); expected.add(2); assertThat(actual, hasItems(expected)); error copi...

Can you help me avoid a kludging JUnit in a master/slave Ant build setup?

We're using the task within our master build to invoke targets in separate ant builds for each of our sub-projects. So far so good, we get things built, we can even run JUnit tasks within each one and everybody is happy. However... We want to take it to the next level, we would like to have a single JUnit report generated from the JUni...

Why doesn't JUnit provide assertNotEquals methods?

Does anybody know why JUnit 4 provides assertEquals(foo,bar) but not assertNotEqual(foo,bar) methods? It provides assertNotSame (corresponding to assertSame) and assertFalse (corresponding to assertTrue), so it seems strange that they didn't bother including assertNotEqual. By the way, I know that JUnit-addons provides the methods I'm...

testNG tests extending BaseTest

Hello, We noticed that when testNG test cases extend TestCase (JUnit) those tests start executing as Junit tests. Also, I should probably mention, the tests are run through Maven. Is this a bug or a feature? Is it possible to override this behavior and still run those types of tests as TestNG tests? Do you know a link where TestNG talk...

Junit4 : expected=Exception not working with SPRING

I'm trying to use the @Test(expected = RuntimeException.class) annotation in order to test for an expected exception. My code is as follows: @Test(expected = RuntimeException.class) public void testSaveThrowsRuntimeException(){ User user = domain.save(null); } and my save method simple like this : publ...

Unit testing DAO, am I doing it right?

I'm starting out unit testing and reviewing Java web programming. The thing is I don't know if I'm doing things right. I'm building a mini blog. I'm using EasyMock for the mock objects. Here's my code: The test case The PostDAO The Post Bean I'd really appreciate your comments and suggestions on how I could improve my code and bec...

Intellij Idea "Move refactoring" with Junit tests

Seems when I make "move" refactoring all my junit tests lays on its old place. Often I tests "package" visible classes, so they becomes invisible, if SUT moves to another package. Do you move tests by hand? ...

JUnit test for System.out.println()

Hi. I need to write JUnit tests for an old application that's poorly designed and is writing a lot of error messages to standard output. When the getResponse(String request) method behaves correctly it returns a XML response: @BeforeClass public static void setUpClass() throws Exception { Properties queries = loadPropertiesFile("req...

Lack of support base class in Junit4/Jmock2

We're finally migrating our unit test code base from JUnit 3 to JUnit 4. We also make heavy use of JMock 2. With JUnit 3, JMock provides a useful base class for your tests (MockObjectTestCase), which as well as itself being s subclass of Junit's TestCase, it handles various housekeeping duties regarding the mock framework. It makes lif...

'new' modifier in Java

Is there an equivalent to C#'s 'new' modifier in Java? I'd like to use it for unit tests - every init() method should be marked final and annotated with @Before. Then, jUnit executes all of these init() methods. I don't want to bother coming up with new names for each of these init() methods, and I definitely wants to mark them as fina...

Break on Exception in Eclipse using jUnit

Is there a way to make Eclipse break on uncaught exceptions while in debug mode for jUnit? Eclipse breaks fine when executing main(). Is there a command-line switch I can use? Thanks ...

Selenium RC - disabling browser cookie

Is it possible to disable a browser cookie using selenium, RC specifically? If so, what is the api call or sequence of calls to make this happen. There is a feature being tested where theres a need to verify the behavior when cookies are enabled or disabled. Thanks ...

Selenium running as junit in ant prematurely closes browser but not in IDE

I've got a bunch of selenium test cases set up in a JUnit class as four methods. The first runs fine - but the remaining three close the Firefox browser before the final step of the method is complete - giving a ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log windo...

Integration Test with Spring: Cannot convert value of type error

I am in the process of developing Integration Test scripts for our spring application. When I run the test from ant I am getting the following error message: Any ideal as why? Testcase: testgetDefaultItemForStoreWithInvalidStoreId(com.xyz.business.admin.role.RoleUtilityUnitTest): Caused an ERROR Error creating bean with name 'groun...

problem compiling a junit test class with ant

Hello, I am having issues integrating junit with a working ant build.xml file. My test class is in the same directory as my source classes. As I am learning how to use ant, I simply want to compile all the source and the test classes. I am using eclipse and the junit test classes work fine when execute through eclipse. Which means the ...

Run Junit-Tests from several projects conveniently fast in Eclipse

Is there a way to run JUnit-Tests from several projects conveniently fast in Eclipse? The JUnit-Runner lets you define a package or a folder where from all contained tests are executed. Is there a way to do this with tests from several projects inside Eclipse? Preferably it should be via the Junit-Runner. If there is some way to have ...

How to best test Java code?

I have been working on a comparatively large system on my own, and it's my first time working on a large system(dealing with 200+ channels of information simultaneously). I know how to use Junit to test every method, and how to test boundary conditions. But still, for system test, I need to test all the interfacing and probably so some s...