junit

In Java how can I validate a thrown exception with JUnit?

When writing unit tests for a Java API there may be circumstances where you want to perform more detailed validation of an exception. I.e. more than is offered by the @test annotation offered by JUnit. For example, consider an class that should catch an exception from some other Interface, wrap that exception and throw the wrapped excep...

Selenium typeKeys strips out dot from the String being typed

The following instruction Selenium.typeKeys("location", "gmail.com"); types the string gmailcom instead of gmail.com. What's happening there? From the comments: I am trying to simulate autofill and the only way to do it currently on selenium is to combine type and typeKeys. eg: selenium.type("assigned_to", split[0]+"@"); selenium.t...

Strategies to mock a webservice

I'm implementing a client consuming a webservice. I want to reduce dependencies and decided to mock the webservice. I use mockito, it has the advantage vs. EasyMock to be able to mock classes, not just interfaces. But that's not the point. In my test, I've got this code: // Mock the required objects Document mDocument = mock(Document.c...

Can JUnit Ant task report ignored tests?

We're currently using JUnit 4.4 and Ant 1.7.1 for our builds. I have some test cases that are @Ignored. When I run them in Eclipse, the JUnit test runner reports them as ignored. I would like to see them listed in the XML output from Ant (so I can report on them), but they do not seem to be there. Does anyone have this working? Is ther...

How to specify an fileset exclude statement pointing to a file in Ant?

Is there a way to have an Ant Fileset->IncludesFile attribute take a property file OR any other file that contains a list of Java class files to exclude? Eg: File A.properties OR A.java contains listing abc.class mno.class xyz.class Is there a way to say to point excludesFile to file A.properties. <fileset dir="..."> <exclu...

Where should I put my JUnit tests?

I've got 2 questions about organising Unit tests. Do I have to put test to the same package as tested class, or can I organise tests in different packages? For example if I have validity and other tests, is it correct to split them into different packages, even if they are for same class? What about mock and stub classes? Shall I sepa...

Is there a way to run Bamboo tests simultaneously??

Currently, I have two selenium-junit tests configured to run on bamboo about the same time. One test runs on MachineA (selenium etc. installed) and the other on MachineB (selenium etc. installed). When kicked off, bamboo builds the one on machineA and enqueues the one on machineB. My question is why cant bamboo handle multithreading? or ...

Grouping JUnit tests

Is there any way to group tests in JUnit, so that I can run only some groups? Or is it possible to annotate some tests and then globally disable them? I'm using JUnit 4, I can't use TestNG. edit: @RunWith and @SuiteClasses works great. But is it possible to annotate like this only some tests in test class? Or do I have to annotate wh...

Setup and Tear Down of Complex Database State With Hibernate / Spring / JUnit

I have a class I'm unit testing that requires fairly extensive database setup before the individual test methods can run. This setup takes a long time: for reasons hopefully not relevant to the question at hand, I need to populate the DB programatically instead of from an SQL dump. The issue I have is with the tear-down. How can I eas...

What is the right combination in ant?

It doesnt seem that when you combine these Fileset attribute like below: eg: <fileset dir="src"> <include name="gov/nasa/arc/mas/selenium/tests/*.java" /> <excludesfile name="${test.suite}.exclude" /> </fileset> that it has the expected behavior which is to include all *.java under src but exclude all the file specified on the...

JUnit theory for hashCode/equals contract

The following class serve as generic tester for equals/hashCode contract. It is a part of a home grown testing framework. What do you think about? How can I (strong) test this class? It is a good use of Junit theories? The class: @Ignore @RunWith(Theories.class) public abstract class ObjectTest { // For any non-null refere...

Run several ant tasks on the same VM

I'm running unit test using ant <target name="test" depends="tomcatDeploy" description="Build and run tests"> <ant dir="${aDir}" target="test"/> <ant dir="${bDir}" target="test"/> <ant dir="${cDir}" target="test"/> <ant dir="${dDir}/ExtFramework" target="test"/> </target> and I want to run them all on the same VM - o...

jUnit - How to assert that inherited methods are invoked?

Let's say you have some 3rd-party library class that you want to extend, simply to add convenience methods to it (so you can call an inherited method with default parameters for example). Using jUnit/jMock, is it possible to write an assertion / mock expection that tests that the correct inherited method is called? For example, somethi...

Where do we start using Unit testing?

Where do we start using Unit testing? I have some doubts about where to start using Unit testing. I am doing unit testing with Junit in RAD. And I am doing it after all code is ready to deploy or may be after deployment. I am confused why we are doing unit testing after code is almost ready to deploy. My question is when we should start ...

How to call Oracle function or stored procedure using spring persistence framework?

Hi, I am using Spring persistence framework for my project. I want to call oracle function or stored procedure from this framework. Can anybody suggest how can I achieve this. Please give solution for both * oracle function and *stored procedure. Thanks. ...

Automated way to find JUnit tests that leak memory

The root of our problem is Singletons. But Singletons are hard to break and in the meantime we have a lot of unit tests that use Singletons without being careful to completely clear them in the tearDown() method. If figure that a good way to detect tests like these is to look for memory leaks. If the memory used after tearDown() and S...

JUnit's MaxCore from ant

Is there a way to use JUnit 4.6's new MaxCore runner from the ant task? ...

UnsatisifiedLinkError with ojdbc14.jar

Hi guys, I am trying to run some JUnit tests that connect to an Oracle database and whether a connection attempt is made. The following error is thrown: oracle/jdbc/driver/T2CConnection.t2cGetCharSet([CI[CI[CII[SLoracle/jdbc/driver/GetCharSetError;)S at oracle.jdbc.driver.T2CConnection.getCharSetIds(T2CConnection.java:2801) at oracle....

JUnit: Possible to 'expect' a wrapped exception?

Hello! I know that one can define an 'expected' exception in JUnit, doing: @Test(expect=MyException.class) public void someMethod() { ... } But what if there is always same exception thrown, but with different 'nested' causes. Any suggestions? ...

Where do I configure log4j in a JUnit test class?

Looking at the last JUnit test case I wrote, I called log4j's BasicConfigurator.configure() method inside the class constructor. That worked fine for running just that single class from Eclipse's "run as JUnit test case" command. But I realize it's incorrect: I'm pretty sure our main test suite runs all of these classes from one proces...