A ready-to-use bootstrap Java project backed by gradle, TestNG, Mockito, FEST-Assert 2 and Cobertura for Eclipse and Jenkins.
- Gradle version 1.3 -- build tool
- TestNG version 6.8 -- unit testing framework
- Mockito version 1.9.0 -- mocking framework
- FEST-Assert 2 version 2.0M8 -- fluent interface for assertions that allows you to write assertions that read more like natural language (unfortunately Java lacks something like the awesome ScalaTest framework)
- Cobertura plugin for Gradle version 1.0 -- allows Gradle to generate Cobertura compatible test reports (mostly used for integrating test results with Jenkins)
Packages only used for showcasing the functionality:
- Google Guava version 13 -- solely used to show how compile-time dependencies are configured in Gradle
The latest dependency information is always available in build.gradle.
We have two complimentary goals:
- You should be able to use Eclipse as the IDE of choice to work with the code (e.g. run the build and tests locally on your machine).
- You should be able to integrate the code with the Jenkins continuous integration server (e.g. to let it run the build and tests for your team and publish the test results).
The first goal covers your personal workflow as a software engineer with the code. The second goal covers integrating the code with the your engineering team as a whole.
- Download the bootstrap project as described below.
- Configure Eclipse (optional).
- Configure Jenkins CI server (optional).
- Hack away!
You have the following two options to start your own project with the bootstrap project.
If you don't have a GitHub account, the simplest way is to just clone (i.e. checkout) the original bootstrap project. The only requirement is a local installation of git on your machine.
$ git clone git://github.com/miguno/gradle-testng-mockito-bootstrap.git
Now you can start hacking away!
$ cd gradle-testng-mockito-bootstrap
# ...start coding...
If you do have a GitHub account, I recommend that you fork the bootstrap project. Then start writing your own code against your personal fork.
First, open the bootstrap project on GitHub and fork it. Then clone (i.e. checkout) your personal fork.
$ git clone git@github.com:YOURUSERNAME/gradle-testng-mockito-bootstrap.git
Now you can start hacking away!
$ cd gradle-testng-mockito-bootstrap
# ...start coding...
The bootstrap project ships with only two classes:
- BobRoss.java -- A simple class that implements a few features that we can write unit tests for. We pretend to be the late painting instructor Bob Ross who, well, is painting a picture with us.
- BobRossTest.java -- This class tests the former class. It illustrates the use of TestNG, Mockito and FEST-Assert 2 to write these unit tests. Don't pay too much attention to the semantics of the actual tests, we're just showcasing here.
Before continuing you must download and install Gradle if you haven't done so already.
If you are on a Mac and have the Homebrew package manager installed, you just need to run:
$ brew install gradle
The bootstrap project is a normal gradle project. Have a look at the
gradle documentation what this allows you to do. I will only list the most
important commands here. If you want to see what gradle tasks are available out of the box in the bootstrap project,
run gradle tasks
.
# General commands
$ gradle clean # deletes the build directory
$ gradle clean test # runs the unit tests (and compile before if needed)
$ gradle clean build # assembles and tests this project
# Eclipse related
$ gradle cleanEclipse # cleans all Eclipse files
$ gradle eclipse # generates all Eclipse files
# IntelliJ IDEA related
$ gradle cleanIdea # cleans all IntelliJ files
$ gradle idea # generates all IntelliJ files
By default, executing the commands above will create output in the following locations:
build/
-- this sub-directory is used by Gradlebuild/reports/cobertura/main/coverage.xml
-- Cobertura test coverage report in XML formatbuild/reports/tests/testng-results.xml
-- TestNG Results in XML formatbin/
-- this sub-directory is used by Eclipse
Feel free to browse the directory tree to find additional files that you might need.
See Bootstrapping a Java project with Gradle, TestNG, Mockito and Cobertura for Eclipse and Jenkins for more information including screenshots.
If you come up with any improvements, feel free send me a pull request.