junit

Does a Unittest has to have an Assertion like "assertEquals(..)"

Hi I have a little JUnit-Test that export an Object to the FileSystem. In the first place my test looked like this public void exportTest { //...creating a list with some objects to export... JAXBService service = new JAXBService(); service.exportList(list, "output.xml"); } Usually my test contain a assertion like assert...

problem of testing file worker in java

Hi I have a question which is described below: What problems would arise for testing a Java class which counts number of words in a file? The function's signature is below: public int wordCount(String filename) Well, this is a junit testing question. If you know the problem, what is the solution of that? ...

Hudson build fails with Git repository & Grails

I recently configured Hudson to build a Grails project using Git as the repository. However, I am getting this error when running the build: Compilation error: srcdir "/home/matthew/.hudson/jobs/qotd-idea/workspace/src/groovy" does not exist This is because src/groovy is not copied into the Hudson workspace, so Hudson can't find the ...

Junit REST tests?

I am using Struts2, Spring 2 and Junit 4.5. My main question is, whether even to test REST calls? Because, basically this are only calls to business logic and they don't have any logic theirs methods. I have tests for all DAO and BL classes, rest xml and json handler, so I don't know what should I even test in REST calls - result code...

Re-running failed and not-run tests.

Let me describe a simple use-case: Running all tests in our project may take up to 10 minutes. Sometimes I see an obvious bug in my code after the first failed test, so I want to stop running all tests, fix the bug and re-run them. Unfortunately, I can either re-run all tests from the beginning, or re-run failed tests only. Is there a...

How do I define a TestSuite without using @SuiteClasses in Junit 4.5?

I'm trying to migrate to JUnit 4 and I'm not clear about the correct way to set up test suites. I know how to set up a test suite with fixed tests using the @SuitesClasses annotation. However, I want to have a top-level suite class, where I can programatically decide which test classes or suites I want to load. I know that there are ad...

Class teardown in junit 3?

We have a lot of integration tests written using JUnit 3, though we're now running them with 4.4. A few of these have a need for a tearDown method that runs after all the tests in the class are complete (to free some common resources). I see that this can be done in junit 4 with @AfterClass (org.junit). However, mixing this into exist...

Is it possible to programmatically generate JUnit test cases and suites?

I have to write a very large test suite for a complex set of business rules that are currently captured in several tabular forms (e.g., if parameters X Y Z are such and such, the value should be between V1 and V2). Each rule has a name and its own semantics. My end goal is to have a test suite, organized into sub test suites, with a tes...

JUnit: How to simulate System.in testing?

I have a Java command-line program. I would like to create Junit test case to be able to simulate System.in. Because when my program runs it will get into the while loop and waits for input from users. How do I simulate that in JUnit? Thanks ...

Source not found: The jar file selenium-java-client-driver.jar has no source attachment

hello, I am creating test cases using Junit framework and eclipse. Once I complete my execution of script I am getting below error: It also gives me the option to attach the source. java.lang.NullPointerException at com.thoughtworks.selenium.SeleneseTestCase.tearDown(SeleneseTestCase.java:395) at junit.framework.TestCase.r...

getting NullPointerException error after executing my test script

Hello, I am using selenium RC with Junit framework and Eclipse. In whole test script, I am just opening one form and update some values in grid table. Some ending lines of code.. selenium.type(prop.gridtxtboxACTL, "test123"); selenium.click("link=Update"); selenium.waitForPageToLoad("30000"); } public void teardown() throws Exception...

Compare Date objects with different levels of precision

I have a JUnit test that fails because the milliseconds are different. In this case I don't care about the milliseconds. How can I change the precision of the assert to ignore milliseconds (or any precision I would like it set to)? Example of a failing assert that I would like to pass: Date dateOne = new Date(); dateOne.setTime(61202...

How to test/design a class which has a private field that needs to be modified inside Junit testing?

Suppose I have a class ClasswithPrivateState which has a private field that depends strictly on the current system state when the object is created. Currently, this field is initialized inside the constructor. But then I got stuck at testing this class since I can't change this private field in my testing method to test some cases. I a...

Changing the default TestRunner in Eclipse.

All tests should be run with jUnit3, if i run a non-configured Test, it tries to use the default-TestRunner (jUnit4). So, i have to go into the run/debug configuration, change the TestRunner to "jUnit3" and run it again. On EVERY Test. This just disturbs the workflow. So, is there an option to REMOVE jUnit4 as possible TestRunner, or ...

CruiseControl JUnit test results show all zeroes

I've got JUnit hooked up with CruiseControl and unit tests are being executed & logs imported, but CruiseControl shows the following output: nz.co.picksend.core.tests.nz.co.picksend.core.dal.FilterTests Tests: 0, Failures: 0, Errors: 0, Duration: 0.0 nz.co.picksend.core.tests.nz.co.picksend.core.dal.ModelObjectRegistryTests Tests: 0, ...

How do I set file.encoding for a junit test in ant?

I'm not quite done with file.encoding and ant. How do I set the file.encoding for junit tests in ant? The junit ant task doesn't support the encoding attribute like the javac task does. I've tried running «ant -Dfile.encoding=UTF-8» and «ANT_OPTS="-Dfile.encoding=UTF-8" ant» without success. System.getProperty("file.encoding") wit...

Testing SOAP endpoint through junit throws SAXParseException (soapenv:Envelope)

Hi all, I've try to implement integration tests for a working application (spring, hibernate, soap, cxf). I build an SOAP-XML by hand and handle it to my endpoint. Like this: private Source createRequest(String domainName, String email, String userId, String password) { String content = ""; content += "<soapenv:Envelope xmlns:s...

Conditionally ignoring tests in JUnit 4

OK, so the @Ignore annotation is good for marking that a test case shouldn't be run. However, sometimes I want to ignore a test based on runtime information. An example might be if I have a concurrency test that needs to be run on a machine with a certain number of cores. If this test were run on a uniprocessor machine, I don't think ...

need suggestions on getting started with Junit

I have not used Junit before and have not done unit testing automatically. Scenario: We are changing our backend DAO's from Sql Server to Oracle. So on the DB side all the stored procedures were converted to oracle. Now when our code calls these thew Oracle Stored Procedures we want to make sure that the data returned is same as comp...

writing test case for a DAO on a J2ee Application

I am trying to write some test cases for my DAO classes in a J2EE applications. Methods in my DAO classes try to get connection to the Database based on a JDBC URL (which is on the app server). So from the front end if I click bunch of stuff and make the DAO trigger it runs fine. However, when I write tests cases for the DAO and the D...