Micro Benchmarking your Tests using JUnit and JUnitBenchmarks

I recently stumbled upon a nice framework that allows to convert simple JUnit tests into micro benchmarks named JUnitBenchmarks. It allows to set basic benchmark options and and to generate charts by adding some simple annotations and a test rule to your tests. One might argue if it is wise to mix the aspects, testing and benchmarking and I’d agree for sure – nevertheless I think this framework can be handy sometimes so let’s create some benchmarks using JUnit and JUnitBenchmarks.. ...

March 10, 2013 · 8 min · 1508 words · Micha Kops

A short Introduction to ScalaTest

ScalaTest is an excellent framework to write concise, readable tests for your Scala or Java code with less effort. In addition it integrates well with a variety of frameworks like JUnit, TestNG, Ant, Maven, sbt, ScalaCheck, JMock, EasyMock, Mockito, ScalaMock, Selenium, Eclipse, NetBeans, and IntelliJ. In the following short tutorial we’re going to write some tests using ScalaTest exploring features like rich matchers, BDD syntax support or web tests using Selenium/Webdriver. ...

January 13, 2013 · 7 min · 1346 words · Micha Kops

Running categorized Tests using JUnit, Maven and Annotated-Test Suites

Sometimes we need to classify the tests in a project and a possible solution to achieve this goal is to assign different categories to the tests. Often we’re doing this to separate the execution of fast-running and long-running tests or to run a specific set of tests that is only applicable in special situations. To run a specific set of categorized tests there are different options and in the following tutorial we’ll be covering two of them: by configuring the Maven Surefire Plug-in or by using a JUnit Test Suite and the JUnit annotations. ...

December 6, 2012 · 4 min · 748 words · Micha Kops

New features in JUnit 4.11

JUnit is one of the most popular testing frameworks out there. Version 4.11 has just been released and offers some nice improvements that you shouldn’t miss. Dependencies In older versions of JUnit there were two dependencies .. junit:junit contained an old version of hamcrest and could cause some nasty trouble .. junit:junit-dep just referenced hamcrest the maven way. Now with version 4.11 there is just junit:junit with clean references to hamcrest and junit:junit-dep is relocated to junit:junit. ...

November 18, 2012 · 4 min · 850 words · Micha Kops

Make your Tests more readable with custom Hamcrest Matchers

Everyday we’re writing tests for our software and sometimes we’re in a situation where we’re testing a specific type or object very often. Luckily Hamcrest allows us to create custom matchers by subclassing from a given variety of available matchers. Adding jUnit and Hamcrest First add the dependencies for JUniti and Hamcrest to your project’s pom.xml or alternative build system. <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-all</artifactId> <version>1.3</version> <scope>test</scope> </dependency> </dependencies> ...

October 28, 2012 · 3 min · 610 words · Micha Kops

Integration Testing IMAP, SMTP and POP3 with GreenMail

Having written some e-mail handling, sending or receiving library you’d like to run some integration tests against a real mail server? Then GreenMail might help you out here .. the framework is not quite new on the market but it is really easy to setup IMAP,SMTP or POP3 services with it and it comes with some helpful libraries making your life a bit easier here. That’s why I’ve come to the idea to share some examples for setting up different server instances, creating user accounts and – at last – fetching and validating e-mails… ...

July 30, 2012 · 9 min · 1833 words · Micha Kops

Arquillian Tutorial: Writing Java EE 6 Integration Tests and more

Now that the long awaited stable version of the Arquillian framework is released I wanted to demonstrate some interesting features of this framework that really eases writing and running of integration tests for Java EE 6 applications in many different ways. In the following tutorial we are going to create some real-world examples using Enterprise JavaBeans, Contexts and Dependency Injection, the Java Persistence API and we’re finally running Drone/Selenium tests against a JEE Web Application that is using Java Server Faces. ...

April 26, 2012 · 8 min · 1576 words · Micha Kops

Selenium WebDriver, Selenium Server and PageObjects by Example

A lot has changed since Selenium RC and WebDriver has given us a new syntax to write tests for our web pages. PageObjects add an abstraction to the pages under test and finally we’re able to programmatically start Selenium server instances and use them to run the tests. In the following tutorial, we’re writing some tests using PageObjects, WebDriver, Selenium Server and finally we’re even taking some screenshots of our tested web pages.. ...

March 6, 2012 · 4 min · 787 words · Micha Kops

Ordering your JUnit Rules using a RuleChain

JUnit Rules are a handy solution if one needs to alter test methods or wants to share common functionality between several test cases. JUnit 4.10 introduced a new class to order several rules according to our needs using a so called rule-chain. In the following example, we’re going to create a simple custom rule and afterwards bind several instances of it in a specified order to a test method. Adding JUnit Just one Maven dependency needed here – JUnit 4.10 ...

February 21, 2012 · 3 min · 560 words · Micha Kops

Oh JBehave, Baby! Behaviour Driven Development using JBehave

Behaviour Driven Development is the keyword when we’re talking about test scenarios written in an ubiquitous language, strong interaction with stakeholders, product owners or testers and well described, common understandable test scenarios. The popular JBehave framework is our tool of choice here and allows us to decouple our test stories from the test classes, offers an integration for web tests using Selenium and finally there’s a helpful Maven plugin for JBehave, too. ...

May 31, 2011 · 14 min · 2849 words · Micha Kops