0

REST Http Client : Feign vs Retrofit 2

AppManager screenshot

I have been recently writing a new REST/Http client for the amazing APM product ManageEngine AppManager. In this context, I had to choose an efficient framework to build a new HTTP Client. I decided to let Netflix Feign and Retrofit 2 fight in the arena.

Continue Reading

1

Developing with S3 and Java : useful links

Amazon S3 Webservices

This article is part of my web research to prepare the development of a new feature using Amazon S3 Webservices.

Continue Reading

3

Java developer testing toolbox

JBehave : code

An article dealing with Java application and testing frameworks and related libraries. Continue Reading

1

Writing an integration test with a mail server

This is a simple example of code to demonstrate how to use the library fakesmtp-junit-runner to write integration tests with mail servers.

The library has been released on GitHub and Maven Central. Continue Reading

0

Test and Data Generation for Java Unit tests

Today I was preparing a presentation about Software Code quality for a TechTalk on Thursday. I made a search on Internet about Automatic Unit test generator and Data Generators. I will present some tools I have tried. Today, we will speak of Randoop.

Randoom Test Generator

Randoom Test Generator

The first tool name is Randoop.. This tool is existing since 2007 and its purpose is to generate automatically unit tests 🙂 Directly from your class definition!

To use it you have two choices:

  • You can use your software JAR or classpath directory.
  • You can include it in your test compile path (on gradle or maven) and creates a main or unit test.

To explain short the theory, thanks to the Java reflection it’s quite easy to produce automatic tests validating some contracts of your API.

Some examples: – toString() should never returns null or throws an Exception – equals() and compareTo() methods have a long list of constraints – Reflexivity: o.equals(o) == true – Symmetry: o1.equals(o2) == o2.equals(o1) – Transitivity: o1.equals(o2) && o2.equals(o3) ⇒ o1.equals(o3) – Equals to null: o.equals(null) == false – It does not throw an exception

Therefore this tool is generating unit tests with JUnit(TestSuite) for the list of classes you provide.

I have done some tests and you can reach 50-60% of coverage quite easily.

The main drawbacks of the solution are: – The unit tests are drawing a snapshot (precise picture) of your code and its behaviour however some tests are really non-sense and you don’t want to edit them. – They don’t replace handwritten tests since the tool is not understand the different between a String parameter emailand fullName. He will mostly use dumb strings.

About the technology, it’s not production ready: – I had troubles with the jar and its dependency plume. – The JAR is a fatjar and coming with dependencies that broke my software.

In conclusion, I will fork the software and try to fix the problems to make it more popular 🙂

1

Release of FakeSmtp-junit-runner

Today, I released a new library to help developers to write integration tests with mail servers.

The library has been released on GitHub and Maven Central.

fakesmtp-junit-runner

Build Status

Coverage Status

Links : github.

Important : Part of the source code of this library has been modified and adapted from the project of FakeSmtp. I want to thank him since his project inspired me the creation of that library.

This library is an extension to JUnit to allow developers to write integration tests where a SMTP server is required.

The how-to is quite simple :

  • Inserts the @Rule in your integration tests
  • a Fake SMTP Server will start
  • You can send mails on it
  • You can control the mailbox
  • Write your own assertions to check mails.

Installation

The project requires JUnit 4.11 or higher. It also requires SLF4J API presents in the classpath. I did not bundle them in the library to avoid conflicts.

To use it, adds the library to your maven or gradle config script :

For maven :

<dependency>
  <groupId>com.github.sleroy</groupId>
  <artifactId>fakesmtp-junit-runner</artifactId>
  <version>0.1.1</version>
  <scope>test</scope>
</dependency>

For gradle :

testCompile "com.github.sleroy:fakesmtp-junit-runner:0.1.1"

Usage

Step 1 :

Creates a JUnit test :

public class SmtpSendingClassTest {


  @Test
  public void testCase1() {

  }

}

Step 2 :

Adds the new Junit rule with its configuration :

public class SmtpSendingClassTest {

  @Rule
    public FakeSmtpRule smtpServer = new FakeSmtpRule(ServerConfiguration.create().port(2525).charset("UTF-8"));

  @Test
  public void testCase1() {

  }

}

Step 3 :

You are ready to use it, controls the mailbox or the server state :

Assert.assertTrue(smtpServer.isRunning());
public class SmtpSendingClassTest {

  @Rule
    public FakeSmtpRule smtpServer = new FakeSmtpRule(ServerConfiguration.create().port(2525).charset("UTF-8"));

  @Test
  public void testCase1() {
    Assert.assertTrue(smtpServer.isRunning());
    Assert.assertTrue(smtpServer.mailbox().isEmpty());
  }

}