Articles Tagged ‘tdd’

Using Throwaway Containers for Integration Testing with Java, JUnit 5 and Testcontainers.

Wednesday, January 30th, 2019

A lot of boilerplate code is written when developers need to test their applications with different connected systems like databases, stream platforms and other collaborators.

Docker allows to handle those dependencies but there is still some glue code required to bind the container’s lifecycle and the configuration to the concrete integration test.

Testcontainers is a testing library that offers lightweight throwaway instances of anything able to run in a Docker container, with bindings to configure the specific containers and also provides wrappers to manage our own custom containers.

In the following short tutorial I am going to demonstrate how to start Apache Kafka as well as a classical Postgresql database from a JUnit 5 integration test.

(more…)

Setting up Kafka Brokers for Testing with Kafka-Unit

Wednesday, March 28th, 2018

When writing test for applications that interact with Kafka brokers we often need to setup a decent environment including an instance of Kafka and ZooKeeper.

Though Kafka ships with some classes for testing, setting up a simple testing environment is quite easier with the kafka-unit library that offers JUnit test rule support or a fast programmatic setup within no time.

In the following short example, I’d like to show how create a simple setup using Maven, Surefire and kafka-unit. (more…)

Implementing, Testing and Running Procedures for Neo4j

Tuesday, February 27th, 2018

A lot of features are already included in the Neo4j graph database system but sometimes we want to extends its capabilities and implement functions and procedures by ourselves that we may reuse.

In the following tutorial I will demonstrate how to implement a procedure for Neo4j, how to write and run tests using JUnit and an embedded graph database and last but not least how to setup Neo4j with Docker and our stored procedure installed in no time.

(more…)

Using JUnit 5 Parameterized Tests, Argument Sources and Converters

Saturday, August 19th, 2017

With JUnit 5 the possibilities to write parameterized tests have changed and improved a lot.

The following short overview covers all new types of possible parameter sources for JUnit 5 tests as well as the new conversion API for test arguments.

In addition we’re showing how parameterized tests were written in JUnit 4.

(more…)

Assuring Architectural Rules with ArchUnit

Monday, July 3rd, 2017

Maintaining architecture rules and constraints for a specific software project or an application is not easy as textual documentation is easily forgotten after a while and hard to verify.

ArchUnit is a testing library that allows developers and software architects to write down such rules as executable tests that may be run by the development teams and the integration servers.

In the following article I will demonstrate the basic features of this library by applying rules and constraints to an existing application.

(more…)

Template Driven Test POJO Generation with Fixture Factory and Java

Tuesday, June 20th, 2017

In our tests we often need to create a bunch of test-objects that are populated with random-data. This data needs to follow specific rules as identifiers need to be unique or must be incremented, string-properties must follow special conventions and so on. In the following short tutorial I will demonstrate how to generate such test data using the Fixture Factory library. (more…)

Writing BDD-Style Webservice Tests with Karate and Java

Thursday, April 6th, 2017

There is a new testing framework out there called Karate that is build on top of the popular Cucumber framework.

Karate makes it easy to script interactions with out web-services under test and verify the results. In addition it offers us a lot of useful features like parallelization, script/feature re-use, data-tables, JsonPath and XPath support, gherkin syntax, switchable staging-configurations and many others.

In the following tutorial we’ll be writing different scenarios and features for a real-world RESTful web-service to demonstrate some of its features.

(more…)

Handling System Properties, Environment Variables, STDOUT/STDERR in JUnit Tests with System Rules

Monday, December 19th, 2016

When important data is written to STDIN/STDOUT and an application relies on specific system properties or environment variables, writing tests is getting more complicated.

System Rules is a collection of JUnit rules that helps us writing Java tests for everything that deals with java.lang.System.

In the following short examples I’d like to demonstrate how to deal with system properties, environment variables, STDOUT and STDERR and capturing both for testing e.g. for some golden master refactoring.

(more…)

Elasticsearch Integration Testing with Java

Tuesday, August 23rd, 2016

When building up search engines, indexing tons of data into a schema-less, distributed data store, Elasticsearch has always been a favourite tool of mine.

In addition to its core features, it also offers tools and documentation for us developers when we need to write integration tests for our Elasticsearch powered Java applications.

In the following tutorial I’d like to demonstrate how to implement a small sample application using Elasticsearch under the hood and how to write integration-tests with these tools for this application afterwards.

(more…)

LDAP Testing with Java: ApacheDS vs Embedded-LDAP-JUnit

Monday, July 4th, 2016

When writing applications that interchange information with LDAP directory services there is always the need to write integration tests for these components and services.

Therefore we need a the possibility to start-up an embedded LDAP server, fill it with test-data and control its life-cycle during the test-phases.

In the following tutorial I’d like to demonstrate two candidates that fulfil this purpose, the ApacheDS test integrations and a small library named embedded-ldap-junit.

(more…)

Layout Testing with Galen, JUnit and Maven

Monday, May 16th, 2016

Writing tests not only to verify the behaviour of a web site but also the correctness of its layout especially for responsive websites is not always easy.

Luckily the Galen Framework eases the task of writing layout tests for us, offering a specialized domain-specific-language to write layout-specifications, it integrates well with Selenium Grid, Sauce Labs or BrowserStack, it offers an easy way to deal with different browser sizes and responsive designs and it generates nice, detailed test reports.

In the following tutorial I’m going to implement a JUnit test for the layout of a blog article of mine to demonstrate Galen’s basic features and the integration of it with JUnit and the Maven build tool.

(more…)

Load Testing Web Applications with Gatling and Maven

Friday, May 6th, 2016

I have written about other performance testing tools for web applications before. Nevertheless I’d like to demonstrate a library for load testing web applications named Gatling in combination with the build tool Maven.

Gatling offers a nice Scala DSL, high performance using Akka, Netty and asynchronous IO and plug-ins for all modern build tools.

In the following tutorial I’m going to show how to record simulations using an HTTP proxy, rewriting simulations in Scala and running and reporting simulations with Maven.

(more…)

Generating JUnit Tests with Java, EvoSuite and Maven

Sunday, February 28th, 2016

Generating test suites for existing code allows us to verify the behaviour of an application before we’re making changes to its code base or for regression testing.

In the following short tutorial I’d like to demonstrate how to derive test suites from an existing Java application using EvoSuite and the EvoSuite Maven plug-in.

EvoSuite offers some nice features like running in a sandbox to avoid dangerous operations, virtual file-system and network and optimizing of different coverage criteria.

(more…)

Testing Asynchronous Applications with Java and Awaitility

Sunday, August 23rd, 2015

Writing tests for asynchronous applications has never been much fun as we’re always struggling with the problem how to determine state changes, handle process terminations, dealing with timeouts or failures and stuff like this.

Awaitility eases this process for us offering a nice DSL, rich support for languages like Scala or Groovy and an easy-to-use syntax that’s even more fun when using it with Java 8′s lambda expressions.

In the following short introduction I’d like to demonstrate writing some tests different scenarios.

(more…)

Mutation Testing with Pitest and Maven

Sunday, May 10th, 2015

Mutation testing makes an interesting addition to the classical test coverage metrics.

They seed mutations (errors) into the code, run the project’s tests afterwards and if the tests fail, the mutation is killed – otherwise it lived and we have a possible indication of an issue with our tests.

In the following short tutorial. I’d like to demonstrate how to setup mutation tests with the PIT/Pitest library and Maven and generate reports.

(more…)

Marrying Java EE and BDD with Cucumber, Arquillian and Cukespace

Wednesday, January 7th, 2015

Having written about the basics of using Cucumber in a Java project in my last blog article, I now would like to demonstrate how to use a similar setup in a Java EE web project with Arquillian and the Cukespace library.

In the following tutorial, we’re going to write a full Java EE web application and add BDD-style tests to the project so that we’re able to test our business layer on the one hand and the user interface on the other hand using Arquillian Drone and Selenium.

(more…)

BDD Testing with Cucumber, Java and JUnit

Sunday, December 28th, 2014

Whether behaviour-driven-development, specification by example or acceptance test driven development is the goal, the Cucumber framework eases our life when we need to  establish a link between the non-technical, textual description for a new feature and the tests that prove that the application fulfils these requirements.

In the following short tutorial I’d like to demonstrate how to add Cucumber to a Java project and how to write feature descriptions and test-cases for each step of these descriptions. (more…)

Running JavaScript Tests with Maven, Jasmine and PhantomJS

Sunday, May 4th, 2014

Sometimes in a project there is the need to run tests for your client-side code, written in JavaScript from a Maven build.
One reason might be that Maven manages a complex build life-cycle in your project and you need a close integration for your JavaScript tests, another one might be that you’re in an environment where it is complicated to install and manage additional software like an integration- or build-server.

(more…)

A short Introduction to ScalaTest

Sunday, January 13th, 2013

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.

(more…)

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

Thursday, December 6th, 2012

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.

(more…)

New features in JUnit 4.11

Sunday, November 18th, 2012

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.

(more…)

Make your Tests more readable with custom Hamcrest Matchers

Sunday, October 28th, 2012

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.

(more…)

Integration Testing IMAP, SMTP and POP3 with GreenMail

Tuesday, July 31st, 2012

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…

(more…)

Arquillian Tutorial: Writing Java EE 6 Integration Tests and more..

Thursday, April 26th, 2012

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.

(more…)

Selenium WebDriver, Selenium Server and PageObjects by Example

Tuesday, March 6th, 2012

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 programatically 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..

(more…)

Ordering your JUnit Rules using a RuleChain

Tuesday, February 21st, 2012

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.

(more…)

Oh JBehave, Baby! Behaviour Driven Development using JBehave

Tuesday, May 31st, 2011

Behaviour Driven Development Keyword Map

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.

After a short excursion into the principles of Behaviour Driven Development we’re going to write and implement test stories for simple acceptance tests and web tests using selenium.

(more…)

Mocking, Stubbing and Test Spying using the Mockito Framework and PowerMock

Sunday, March 27th, 2011


Today we’re going to take a look at the Mockito framework that not only does sound like my favourite summer cocktail but also offers nice testing, mocking/stubbing, test-spying features and mock injections.

After that we’re going to take a look on how to mock static or final classes by extending Mockito’s capabilities with PowerMock.

(more…)

Search
Categories