At work we are currently still using Junit3 to run our tests. We have been considering switching over to Junit4 for new tests being written but I have been keeping an eye on TestNG for a while now. What experiences have you all had with either Junit4 or TestNG and which seems to work better for very large numbers of tests. Having flexibi...
I am working on a small webapp and I want to use Groovy to write some unit testing for my app. Most of my coding is done on Eclipse and I really want to run all the unit testing with the graphical test runner within Eclipse (I really like the green bar :) )
Sadly, after 4 hours of try-and-error, I'm still not able to setup properly. I t...
How do I use jUnit to test a class that has internal private methods? It seems bad to change the access modifier for a method just to be able to run a test. Thanks.
...
I have a Singleton/Factory object that I'd like to write a JUnit test for. The Factory method decides which implementing class to instantiate based upon a classname in a properties file on the classpath. If no properties file is found, or the properties file does not contain the classname key, then the class will instantiate a default im...
I've been trying to implement unit testing and currently have some code that does the following:
query external database, loading
into a feed table
query a view,
which is a delta of my feed and data
tables, updating data table to match
feed table
my unit testing strategy is this:
I have a testing database that I am free to manipula...
I have a bunch of servlets running under the Tomcat servlet container. I would like to separate test code from production code, so I considered using a test framework.
JUnit is nicely integrated into Eclipse, but I failed to make it run servlets using a running Tomcat server. Could you please recommend a unit testing framework that suppo...
I am writing a unit test to check that a private method will close a stream.
The unit test calls methodB and the variable something is null
The unit test doesn't mock the class on test
The private method is within a public method that I am calling.
Using emma in eclipse (via the eclemma plugin) the method call is displayed as not bei...
What GUI should use to run my JUnit tests, and how exactly do I do that? My entire background is in .NET, so I'm used to just firing up my NUnit gui and running my unit tests. If the lights are green, I'm clean.
Now, I have to write some Java code and want to run something similar using JUnit. The JUnit documentation is nice and clear ...
Most of our Eclipse projects have multiple source folders, for example:
src/main/java
src/test/java
When you right-click on a class and choose New JUnit Test, the default source folder for the new test is "src/main/java" (presumably the first source folder listed in the project properties).
Is there any way to change the default sou...
I'm trying to preform setup and teardown for a set of integration tests, using jUnit 4.4 to execute the tests. The teardown needs to be run reliably. I'm having other problems with TestNG, so I'm looking to port back to jUnit. What hooks are available for execution before any tests are run and after all tests have completed?
Note: we're...
Is there a way to mock object construction using JMock in Java?
For example, if I have a method as such:
public Object createObject(String objectType) {
if(objectType.equals("Integer") {
return new Integer();
} else if (objectType.equals("String") {
return new String();
}
}
...is there a way to mock out...
Hi! I'm running some JUnit tests on my applications. Every test has a for loop calling respective method 10000 times.
The tested methods produce a lot of log.
These logs are also automatically collected by JUnit as test output.
This situation takes to OutOfMemoryError because the string buffer where JUnit keeps the output becomes too la...
There is a well-known debate in Java (and other communities, I'm sure) whether or not trivial getter/setter methods should be tested. Usually, this is with respect to code coverage. Let's agree that this is an open debate, and not try to answer it here.
There have been several blog posts on using Java reflection to auto-test such metho...
Our Java code (not the test code) reads files from the current directory, which means the working directory needs to be set properly whenever we run the code.
When launching a JUnit test from within Eclipse, a launch configuration automatically gets created. The problem is, that the working directory in that launch configuration is alwa...
I am running JUnit through TextMate, and when I try to run my test cases I get this error
JUnit version 4.5
Could not find class: ProgTest
Time: 0.001
OK (0 tests)
Progtest.java can be found here
...
When running all my tests in Eclipse (Eclipse 3.4 'Ganymede'), one test is listed under "Unrooted Tests". I'm using Junit 3.8 and this particular test extends TestCase. I do not see any difference between this test and the other tests. I don't remember seeing this occur in Eclipse 3.3 (Europa).
Clarification:
We haven't moved to JUnit ...
I'm currently looking for ways to create automated tests for a JAX-RS (Java API for RESTful Web Services) based web service.
I basically need a way to send it certain inputs and verify that I get the expected responses. I'd prefer to do this via JUnit, but I'm not sure how that can be achieved.
What approach do you use to test your we...
I am running my junit tests via ant and they are running substantially slower than via the IDE. My ant call is:
<junit fork="yes" forkmode="once" printsummary="off">
<classpath refid="test.classpath"/>
<formatter type="brief" usefile="false"/>
<batchtest todir="${test.results.dir}/xml">
<formatter...
We have a large codebase that takes approx 12 minutes on the developer machines to auto-generate some Java 5 classes using JavaCC and then compiles all the classes as well as running the units test.
The project consists of multiple projects which can be built in groups, but we are aiming for a full a build in under 10 minutes
What tips...
Hello,
I am relatively new to matchers. I am toying around with hamcrest in combination with JUnit and I kinda like it.
Is there a way, to state that one of multiple choices is correct?
Something like
assertThat( result, is( either( 1, or( 2, or( 3 ) ) ) ) ) //does not work in hamcrest
The method I am testing returns one element of...