2014/09/04

Java TDD = PROJECT + ANT + JUNIT

About

This blog is about what issues I have faced and tackle on writing a JAVA project with TDD (Test driven development). As you may not know, I am not an experienced Java developer. All the java coding skills came from a course 2 years ago.

Project

My goal is building up an application for fetching concert’s information from EVENTFUL. Although there is an official java binding provided, some of it’s dependencies (eg: XML) are not supported on ANDROID device by default. So, I am going to make a new one.

ANT

For brevity, I will say this tool works like grunt or makefile which ease the burdens of testing and compile your source code.
Typically, it required a makefile named as build.xml
Structure of the build.xml
XML := 1 * Project
Project := 1~N * Target
Target := 1~N * Task

FAQ

JUNIT

A popular testing framework. To be honest, all I need is the fabulous assertions.

FAQ

  • Installation on MAC BOOK AIR (MAC OS)
Command sudo port install junit works well. Make sure you have updated your port database if you are fail to issue the above command.
  • Compilation on command line
PATH is the most difficult issue in this part. Make sure you have included both junit.jar and hamcrest-core.jar on compilation.
  • How to run JUNIT on command line
2 points to note. The first one is make sure you have included all jar files on your java class path. The second one is how you call your test class. Below is an example
/opt/local/share/java/junit.jar:/opt/local/share/java/hamcrest-core.jar:.:./com/ideafactory/dataquery/test/PerformerTest.class org.junit.runner.JUnitCore com.ideafactory.dataquery.test.PerformerTest

沒有留言:

張貼留言