Tag: Tutorial

Recently, I had a task to migrate the unit tests in our project from ‘JUnit 4’ to ‘JUnit 5’. As many developers, I researched a bit to learn about the major differences between the two versions and drafted a plan for smooth migration.

From the first look, I thought my only job was refactoring the tests and probably some helper classes. But, I was wrong! I ran into a configuration issue with the maven-surefire-plugin configuration.

In this post, I will be sharing the encountered issue and its fix. Note that I will not cover the detailed steps of how to migrate from ‘JUnit 4’ to ‘JUnit 5’.

Tests run: 0!

We, as many other developers, use the maven-surefire-plugin to run our tests during the test phase of maven’s build lifecycle. We rely heavily on this plugin because it fails the build when one of the tests is broken!

With JUnit4, everything was working perfectly! But after the migration, the plugin was always reporting that not tests are run:

'Tests run: 0, Failures: 0, Errors: 0, Skipped: 0 ...'!

Calculator Class

For the purpose of this blog, let us assume we want to build a Calculator. For now, we only have the ‘add‘ method implemented as shown below.

You might come across a situation when working with Git where you want to move a repository to another repository (i.e., make it a subdirectory of the other` repository) while maintaining its full history.

In this blog, I will be pointing out step by step with an example how to achieve that.

Use Case

Let us assume we have two repositories on git, repoA, and repoB, and we want to make repoB a subdirectory of repoA while maintaining its full history.

To achieve that we will move the content of repoB into a subfolder under repoB and then merge repoA and repoB.

Bellow is the detailed git process:

The first step is to clone repoA and repoB on your machine

$ git clone repoA

$ git clone repoB

Note: For the purpose of this blog I submitted a README.md file in each of the two repositories on Bitbucket. Below are two snapshots are taken for both repositories:

RepoA:

RepoB:

The second step is to copy the content of repoB to a subfolder. Go to the folder repoB and apply the following steps:

create a subfolder repoB

$ mkdir repoB

move everything from the parent repoB to the child repoB (except the .git folder)

stage the files (the added folder and deleted file(s)) for a later commit

$ git stage repoB/

$ git stage README.md

commit and push those changes to git

$ git commit -am '[REPO-B] Move content to a subfolder'

$ git push origin master

Go to the folder repoA and do the following:

add a remote branch with the content of repoB

$ git remote add repoBTemp (path_to_repoB)

fetch repoBTemp the temp repo we created in the previous step

$ git fetch repoBTemp

merge repoBTemp with repoA

$ git merge repoBTemp/master

delete the remote repoBTemp

$ git remote rm repoBTemp

push the changes to the server

$ git push origin master

Now we can check our git history to verify that our trick worked as intended. In the right image below you can see that the history of repoB is now part of repoA’s history. In the left image, you can notice that repoB is now a subdirectory of repoA.