Wednesday, 25 April 2018

When would I choose basic HTTP libraries rather than using RestAssured?

TLDR: when I have a small set of HTTP use-cases, and I’m working on fast in-build HTTP integration verification then I’ll probably use HttpURLConnection

I do receive a question fairly often like:

  • “Why would you ever use basic HTTP libraries rather than Rest-Assured?”
  • “When would you choose to use basic HTTP libraries instead of Rest-Assured?”

And other variants.

I’ll try to answer that in this post.

Tuesday, 24 April 2018

Migrating from JAXB XML processing to XStream

TLDR: refactored to isolate XML processing, configured XStream in code, removed all annotations, added XML header, wrote less code

I have a small REST API application which uses Spark and GSON and JAXB. I haven’t released this to Github yet but I did release some of the example externally executed integration verification code for it.

When trying to package this for Java 1.9 I encountered the, now standard, missing JAXB, libraries. So I thought I’d investigate another XML library.

Monday, 9 April 2018

Changes to Automating a REST API code base for Java 1.9 RestAssured 3.0.7

TLDR: For Java 1.9 upgrade Rest Assured to version 3.0.6 0r 3.0.7. I also had to add some JAXB Maven Dependencies

I my book Automating and Testing a REST API I used Java 1.8 and Rest Assured version 3.0.1. This was in the days prior to Java 1.9 becoming the default.

I recently checked the code against Java 1.9 and had to make some changes to update Rest Assured.

Sunday, 8 April 2018

How to learn Java with Exploratory Programming

TLDR: Learn Java by taking advantage of code completion and JavaDoc in the IDE to explore classes with JUnit Tests

In my book Java For Testers I encourage the reader to experiment when learning Java by writing small JUnit tests to explore classes. I’m going to expand on that concept in this blog post and the associated video.

Thursday, 7 December 2017

How to organise resource files for tests using Maven and Java

Resources are a very useful concept in Java. They are essentially files in the project which are compiled into the .jar

Java also has commands for finding them .getResource and reading them .getResourceAsStream

Very Handy.

But, they can be hard to wrap your head around. As evidenced by my own experiences trying to use them and the number of queries on stack overflow.

Friday, 13 October 2017

Simple ways to add and work with a `.jar` file in your local maven setup

TL;DR Hack - add as a library in IntelliJ project. Tactic - add as system scope in maven. Tactic/Strategic - install locally to .m2. Strategic - use a repository management tool, publish to maven central

Sometimes you want to work with a jar file that isn’t hosted in maven central.

It might be a 3rd party jar, it might be one that you have written.


You have a lot of options for this. The approaches that I have used:

  • add .jar files as an IntelliJ project dependency
  • install it locally to your .m2 repository
  • add it to your project as a system scoped file
  • use a repository management tool: like Nexus or Archiva
  • publish the dependency to maven central

Thursday, 12 October 2017

How to Diff Java Code in IntelliJ - 3 ways to use the Compare Tool

TL;DR IntelliJ has an inbuilt diff tool which you can use to compare files, classes or code with the clipboard. Just right click and choose Compare.

I was busy refactoring code in RestMud this morning because I want to try and open source the basic game engine, and then later the Web/REST API, but I want to tidy up the code a little first.

I’ve been working through the code:

  • moving classes into new packages
  • splitting classes to make code clearer and easier to manage
  • new classes make code easier to test

And the more I tidy it up in general, the easier it is to spot smaller problems of code duplication.