Episode IV – JUnit Awakens

Welcome back to a series of blogposts about how to set up a little server in a Linux Virtual Machine, in this post we will lean JUnit and status

if you are not familiar to the topic you can go to the first, second or third part of the series

JUnit via command line

Set up (again?)

First be sure you have Java in the machine (We did this in the last part)

Lovely Ubuntu LTS Interface

Be sure you can compile Java files

I created a class so we can see everything is working fine

Download Junit archive

Download latest version of JUnit jar file from http://www.junit.org, the easiest way in Ubuntu TLS is the wget command. (link in image description)

So type: wget https://github.com/downloads/junit-team/junit/junit-4.10.jar

Create actual tests

My Hello class was pretty much useless. So I take the example from the JUnit Team. And I created two files (these are literally copy-pasted from their repo: https://github.com/junit-team/junit4

Compile!

We have to do the command javac -cp .:junit-4.XX.jar:hamcrest-core-1.3.jar Calc^CatorTest.java (remove the XX for your version)

In my case since I have the junit-4.10.jar, I put 10

Run the test

Enter the command:

java -cp .:junit-4.10.jar:hamcrest-core-1.3.jar org.junit.runner.JUnitCore CalculatorTest

Oh lala, JUnit is running at Ubuntu LTS!

Setup status page

It’s time to do some testing with our cron jobs. First I’ll power up my server.

Remember node command doesn’t exist in our environment, instead it’s nodejs.

So then I implemented a logger in my JUnit tes for the CalculatorTest.java, based on this post of stack overflow

Logger in my test

And I also created a file watcher in my serve so when it detects that my file with the error output it writes “Build” in my readme

npm install node-watch
So sadly it just change the file when it pass, but it doesn’t push it for some reason 😦

I had a very bad time with this easy example. So I don’t wanna know about the professional DevOps (DevOperators?)

Readme Test

How could you update the README page on your repository to reflect the build status using this setup?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s