Two Java Beginner Coding Tips

Two Java Beginner Coding Tips

2 minute read - Java For Testers

Published

TLDR; Coding Tips for beginners.Write your code as temporary comments, remove syntax errors as soon as you see them.

Here are a few tips I’ve been verbally passing on when teaching people on my Java For Testers face to face training.


JUnit5 Assertion Migration Strategy

JUnit5 Assertion Migration Strategy

5 minute read - Java For Testers

Published

TLDR; Rather than migration your assertions line by line, create an abstraction class to represent the new implementation and then perform inline refactoring.

I’m experimenting with migrating my projects to JUnit 5.

Many of the “how to migrate to JUnit 5” blog posts show differences, but not a lot of strategies. I used a Branch By Abstraction strategy to migrate JUnit 4 Assertions. This allowed me to experiment with using JUnit5 assertions or AssertJ assertions.


MVP and API Thinking When Coding

MVP and API Thinking When Coding

10 minute read - Java For Testers

Published

TLDR; Apply MVP principles when coding. Code to the API first. The API is internal before it is external. Unit tests with classes. In code testing with classes in combination. In code API testing. External HTTP API Testing. And then if necessary -In memory and process HTTP API testing. GUI.

A long time ago, in a town which I no longer live in, I wrote a tool called Compendium-TA

Commercially that was a disaster: it was self funded, it took a long time to write and I made some poor technology decisions.

I learned MVP and API First Thinking the hard way. I’ll try and explain within.


Overview Of Spark Java Webserver Testing

Overview of Spark and HTTP Testing with JUnit

4 minute read - REST API Java For Testers

Published

TLDR: Spark is static so having it run in an @BeforeClass allows HTTP request testing to begin.

I use Spark as the embedded web server in my applications. I also run simple HTTP tests against this as part of my local maven build. And I start Spark within the JUnit tests themselves. In this post I’ll show how.


Migrating From Jaxb XML To Xstream

Migrating from JAXB XML processing to XStream

6 minute read - REST API Java For Testers

Published

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](https://github.com/eviltester/automating-rest-api) 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.


Resource Files For Tests

How to organise resource files for tests using Maven and Java

3 minute read - FAQ Maven Java For Testers

Published

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.


Maven Local Dependencies

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

5 minute read - Maven Java For Testers

Published

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

Maven Local Dependencies image

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.

Regardless.

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