junit

What java version is needed for JUnit 4.8

I am trying to run JUnit test with a 1.5 JRE, but get the error Message: java.lang.UnsupportedClassVersionError: Bad version number in .class file When I switch to JRE 1.6 (actually a JDK but that shouldn't matter, right?) everythings works fine. So the questions are: Do we really need Java 6 for the current JUnit version? what is ...

How to use @BeforeClass and @AfterClass in JunitPerf?

Hi, I want to do some actions before the whole test suite (also after the suite). So I wrote like: public class PerformanceTest extends TestCase { @BeforeClass public static void suiteSetup() throws Exception { //do something } @AfterClass public static void suiteSetup() throws Exception { //d...

Is the test suite setup method executed once for each test, or only once for all?

I know the answer may differ for each test framework. But for the ones you know, what should happen? ...

Best testing framework?

Is JUnit the best unit testing framwork? Which framework is best for new java projects? ...

C# testing framework that works like JUnit in Eclipse?

Hello all, I come from a Java/Eclipse background and I fear that I am spoiled by how easy it is to get JUnit and JMock running in Eclipse, and have that GUI with the bar and pass/fail information pop up. It just works with no hassle. I see a lot of great options for testing in C# with Visual Studio. NUnit looks really nice because it co...

NetBeans Platform Unit Test Library Dependencies

I am working on a Netbeans Platform RCP application. I use jmock in my unit tests and I have created a Library Wrapper Module to import the necessary libraries. The Module has an section named 'Libraries' and another section named 'Unit Test Libraries'. I hoped that I could add the JMock Library Wrapper to the 'Unit Test Libraries', h...

JUnit won't stop at breakpoints in Eclipse (using JDK 1.6.0.20)

Hi, my breakpoints in Eclipse won't stop the execution of a JUnit test. It doesn't matter where I set the breakpoint in the JUnit method, it simply won't stop the code from flowing. Placing it in a class called in the JUnit test won't work either. I am using the JDK in the version of 1.6.0.20, so I guess I'm not affected by the bug in ...

The "is" in JUnit 4 assertions

Is there any semantic difference between writing assertThat(object1, is(equalTo(object2))); and writing assertThat(object1, equalTo(object2))); ? If not, I would prefer the first version, because it reads better. Are there any other considerations here? ...

Runtime exception when creating Bundle in JUnit test

I'm testing some Java code that uses an android Bundle, and am getting a runtime exception whenever I create a Bundle in the unit test. The error I'm getting is java.lang.runtimeException at android.os.Bundle when I create the Bundle. It is running with the android SDK in the run configuration. Has anyone run into this problem before? Th...

JUnit Best Practice: Different Fixtures for each @Test

Hi I understand that there are @Before and @BeforeClass, which are used to define fixtures for the @Test's. But what should I use if I need different fixtures for each @Test? Should I define the fixture in the @Test? Should I create a test class for each @Test? I am asking for the best practices here, since both solutions aren't cl...

Junit : add handling logic when exception is not expected

I am trying to print the stack trace of the exception. However, for negative test case, only the unexpected exception is printed. I am using the @Rule ExpectedException to do the exception detection. I don't know how to add handling logic in case an unexpected exception is thrown. @Rule public ExpectedException thrown = ExpectedEx...

Junit run not picking file src/test/resources. For file required by some dependency jar

Hi, I m facing a issue where test/resource is not picked,but instead jar's main/resource is picked Scenario is like : Myproject src/test/resources--- have config.xml w which should be needed by abc.jar which is a dependecy in Myproject. When running test case for Myproject its loading config.xml of abc.jar instead of Myproject test/res...

Wicket, Spring and Hibernate - Testing with Unitils - Error: Table not found in statement [select relname from pg_class]

Hi there. I've been following a tutorial and a sample application, namely 5 Days of Wicket - Writing the tests: http://www.mysticcoders.com/blog/2009/03/10/5-days-of-wicket-writing-the-tests/ I've set up my own little project with a simple shoutbox that saves messages to a database. I then wanted to set up a couple of tests that would ...

Wrapping JUnit Tests (in Eclipse)

All of my tests for my Groovy code look like this public void testButtons() { try { page.getButtons(); } catch (Exception e) { throw org.codehaus.groovy.runtime.StackTraceUtils.sanitize(e); } } because I need to sanitize any possible StackTrace that appears (otherwise it's very hard to read since it'...

Eclipse JUnit Plugin Test very slow to re-execute Test Suite on Windows

I'm having an odd, and stressing, problem with running a large JUnit Plugin test suite in Eclipse. When I try to re-run a JUnit plugin suite that has just been executed, Eclipse hangs for quite some time before it eventually wakes up and launches. It can take up to 5 minutes sometimes, and increases with the size of the suite. Visually, ...

How to ignore a test within the JUnit test method itself

We have a number of integration tests that fail when our staging server goes down for weekly maintenance. When the staging server is down we send a specific response that I could detect in my integration tests. When I get this response instead of failing the tests I'm wondering if it is possible to skip/ignore that test even though it ...

JUnit Custom Rules

JUnit 4.7 introduced the concept of custom rules: http://www.infoq.com/news/2009/07/junit-4.7-rules There are a number of built in JUnit rules including TemporaryFolder which helps by clearing up folders after a test has been run: @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); There's a full list of built in rules ...

JUnit test cases for method which may include call to other methods

Hi I am new to Junit.I am using JUnit 3.8. My problem is,the methods of my application involve database operations(insert,update,delete...) and also one method may have call to number of other methods. I am hardcoding the input values in the test cases.So for the first time the test case,for example record insertion, passes.For the seco...

Is there a way to force JUnit to fail on ANY unchecked exception, even if swallowed

I am using JUnit to write some higher level tests for legacy code that does not have unit tests. Much of this code "swallows" a variety of unchecked exceptions like NullPointerExceptions (e.g., by just printing stack trace and returning null). Therefore the unit test can pass even through there is a cascade of disasters at various point...

JUnit, test and threads

Hi, when i run multiple JUnit tests in a row, does JUnit create a new thread for each execution or everything is wrapped in a single thread? Thanks ...