Wednesday, December 18, 2019

Creating a Coding Story (Coding Stories) with STS or Eclipse is a wonderful tool for senior developers to spread the knowledge of craftsmanship through an organization. Here is a good tool chain for doing this with STS/Eclipse:
  • Maven
  • JUnit 5
  • Git
Why Maven? Unless you want to assume all your Coding Stories readers will be using your IDE of choice (or let them work out setting up the dependencies), use Maven to abstract away your IDE for dependency management.
Why JUnit5? Because it's the most modern and is now well integrated into IDEs.
Why Git? Because that's what Coding Stories uses for integration.


Using STS's wizard, build a Maven project.

The below seems to be the simplest POM type.

Run the maven build and at should successfully build the Maven HelloWorld application.  (See troubleshooting if not.)

Rename the "project" folder per Coding Stories convention.  (I needed to add "-java" onto the end.) Later, this will be our Git repository.

The next section describes how to adjust the POM file and IDE to handle JUnit 5.

JUnit 5

Although IDEs have JUnit 5 integration, many of them default to JUnit 4. The following POM describes how to use JUnit 5 in your Maven project:

<project xmlns=""


 <name>TDD going from Hello World to Mocking</name>

  <!--JUnit tests depend on the engine artifact to build-->

    <!-- Maven by default doesn't support Java 13 so the below sets that up -->


What this does:

  • POM boiler plate: The first paragraph tells XML parsers about the schema to use for validation and declares the namespace.
  • project identity: your project information here
  • package the build as a Jar (required to package it into something)
  • dependencies: JUnit Jupiter is declared here
  • build/plugins: 
    • Maven plugin: 
      • Since I'm building with Java 13, I declare a modern version of the maven plugin to be used when building, 3.8.1 (you see, maven itself is a plugin).  The default maven plugin doesn't support newer versions of Java.
      • Configure the maven plugin to use Java 13
    • Surefire plugin: used to execute unit tests.
Configure the IDE's project to use JUnit 5:

 Add a simple JUnit 5 test to test the configuration and run it from Eclipse.

package biz.agilenoir.helloworldmocking;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class HelloWorldTest {
void test() {
fail("Not yet implemented");
 Run the test and observe that it fails.

Run the test from Maven.  Watch the console for the test report.

If you want to see the test pass, make a change, then run the unit test.  All that's left is to configure Git for CodingStories.

By the way: regarding TDD

Check out the Agile Thoughts podcast.  This podcast gets the Confessions Of An Agile Coach's endorsement (naturally, since the same people produce it) of quality materials for developers and teams trying to get coding done in a way that avoids dealing with legacy issues such as bugs and hard to maintain code.  Agile Thoughts has a lot of great TDD conceptual content along with a radio drama about the difficulties to getting a TDD initiative started.  Click the podcast cover below or here for more information.

Configure Git

Using STS, create a Git repository inside your workspace (there is some controversy over whether this is the best use of Git, but as there is controversy and "no one right way" I think it's alright in this case.)

The project now has "badges" for M-maven, J-java, and a little gold storage icon for Git.

Write your Coding Story

Now that your environment is all tested out. It's time to build your coding story.  Follow "how to" at CodingStories to create your story. When you're finished, tell all your software developer friends and co-workers all about it.  Send them links.  Brag to your boss.  You know, socialize your tools to help others.

 XXX Link to my own coding story coming soon to here XXX

Tweet me if you get stuck: @LancerKind



Problem: Maven build gives me the following:

[ERROR] Source option 5 is no longer supported. Use 7 or later.
[ERROR] Target option 5 is no longer supported. Use 7 or later.
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------

Solution:  Maven defaults to Java 1.6 and will default to a version of the maven plugin that won't work with java 9 or higher unless changes are made in "configuration" (

 Problem: Can't execute unit test in STS

Solution: Click "OK" and setup a run configuration for JUnit 5.

Problem: "$ mvn test" (Maven) doesn't execute find my unit tests.

Solution: Use the Surfire plugin.  See it as the second plugin declared below.

No comments:

Post a Comment