junit

How can I Unit Test Gestures in android?

I want to unit test a swipe left/right action on the screen in Android but I haven't been able to find any documentation on it. Can anyone lend a hand? Can it even be done? ...

JUnit testcases for PDF File

My java program writes information on PDF form. Does anyone know a good way to write test cases using JUnit to make sure it has printed the required information on PDF form. ...

taking output on console when running junit through ant script

i am using ant script and running a junit, the problem i am facing is that i am unable to get the output on console, rather i get the output in a log file. how can i achieve that.. i am using the following script. <target name="validate_mapping" description="Testing the Hibernate "> <path id="validator.classpath"> ...

better jUnit test coverage needed

Good evening everyone Suppose your code has the following statement: if (string ends with char 'y') { if ((char before last is not 'e') || (char before last is not 'a')) { return (something awesome); } } So that's simple enough i thought ... Test1: input = "xy" (last char is y, char before last is not e or a) Result - part...

How do I make a WAR archive produced with maven-assembly-plugin available for other projects' unit tests?

My problem consists of two maven projects, a server project A and a client project B. A uses maven-assembly-plugin to produce several variants of A, where one variant is a WAR archive. The problem I am facing relates to the test-driven development of B; how can I make the WAR archive produced in project A accessible/addressable from unit...

Run JUnit Test suite from command line

How do I run a Junit 4.8.1 Test suite from command line ? Also I want to use the categories introduces with JUnit 4.8 , is there a way where I can specify from command line the category which I want to run. ...

Run all the junit tests that are in a given package in Netbeans?

We have a bunch junit tests in our current project. Essentially we are looking for a way to run all the test in a given package. Currently in Netbeans I see you can run all the tests or a single test, but no way to run a a sub-set of tests. Is this built into Netbeans? Or is there another way we can do this? ...

Cannot initialize EntityManager in Netbeans via Junit

I have a bunch of service (ejb 3) classes that i want to unit test. In order to do so, i have added to their implementing classes an overloaded constructor which takes an EntityManager as an argument. The idea is that during my units tests i will create a both an EntityManager instance from a persistence unit specific for my unit tests, ...

JUnit java.lang.NoSuchMethodError: junit.framework.ComparisonFailure.getExpected()Ljava/lang/String

I am getting the following exception from a test case that ran successfully before but now it throws this exception: java.lang.NoSuchMethodError: junit.framework.ComparisonFailure.getExpected()Ljava/lang/String; at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:63) at org.junit.runn...

Generating JUnit stubs for new methods in existing class in Eclipse

This question is tangentially related to How can I create JUnit stub methods in eclipse? but it doesn't answer my specific question. Assuming you have an existing JUnit test case class, if you add a method to the target class (or choose to test a previously untested method), is there a way to tell Eclipse to generate the stub for the "n...

Junit to test concurrency

Hi, I'm trying to test java.util.concurrent.ConcurrentLinkedQueue when accessed via multiple threads. Mentioned below is my Junit test using RepeatedTest to run in two concurrent threads. My questions is: is it correct to use RepeatedTest to test concurrency for example on ConcurrentLinkedQueue? The source code is mentioned below. Than...

JUnit for getters and setters

As it was highly recommended in one of the books I'm reading I've started to write tests for each of the class I'm creating. I'm not really sure what is a good practice to cover setters and getters or not. If yes I'm not sure how because to verify the setter method you need to call the getter for this variable and vice versa. So you will...

RFT and JUnit Related Issue

I was trying to create a Junit Testing framework within an existing RFT framework. The JUnit set up works fine to the point where we don't have to instantiate any framework classes.Whenever we are trying to access framework classes it throws the below exception. I did look for similar issues online but couldn't get a solution.Please sugg...

JUnit4 fail() is here, but where is pass()?

There is a fail() method in JUnit4 library. I like it, but experiencing a lack of pass() method which is not present in the library. Why is it so? I've found out that I can use assertTrue(true) instead but still looks unlogical. @Test public void testSetterForeignWord(){ try { card.setForeignWord(""); fail(); } catch (Inco...

Checking for a time-out in a JUnit test case

I have a JUnit test case where I'm expecting a particular method call to take a long time (over a minute). I want to Make the method call. Make sure the method call takes at least a minute and have a JUnit assertion fail if it doesn't. Then kill the method call (assuming it took more than a minute as it should) because it could take a...

How can I have the Ant JUnit task run all tests and then stop the rest of the build if any test has failed.

I'm running JUnit via Ant using a target something like this: <target name="junit" depends="compile"> <mkdir dir="${report.dir}"/> <junit printsummary="yes" haltonfailure="yes" showoutput="yes" > <classpath> <path refid="classpath"/> <path location="${classes.dir}"/> </classpath> <...

Weird problem using JUnit in multi-thread environment

Hi all, I meet a weired problem when using JUnit in multi-thread environment. The following code should fail, but it actually pass in eclipse. public class ExampleTest extends TestCase { private ExecutorService executor = Executors.newFixedThreadPool(10); private volatile boolean isDone = false; public void test() throw...

Problem with LowLevelHttpTransport in unit tests

I'm currently trying to run some unit tests on a class that uses HTTPtransport and is part of an Android application. The docs for google-api says that this should be fine since the Apache transport is built into Android. However, when running my tests I get the following error: java.lang.IllegalStateException: unable to load Net...

Can I test status bar notifications using Android's testing framework?

I have a class that sends a status bar notification in Android. I can't find a way to test whether the notification was sent or not, which makes it very hard to write any kind of useful unit test. Does anyone have a solution for this? ...

Asserting exceptions in Java, how?

This might be a conceptually stupid question, but it also might not and since I am still a student I think I should I have no problem asking. Imagine you have a method that if given certain conditions it will throw an NumberFormatException. I want to write a Unit Test to see if the exception is being correctly thorwn. How can I achieve ...