Now it's time to demonstrate your ability to use objects in the Java programming language with TDD.
This repository contains a project for Eclipse that lets you demonstrate your proficiency with test-driven development. It uses the JUnit 4 testing library for unit testing, a very popular TDD library for Java.
Your goal is to work out how to fix the one broken test and then implement the next two requested features by writing a test first, then implementing the method. You'll use Git to demonstrate you have written your tests before you have written your implementations.
Please read all instructions before starting. Important grading criteria follow!
- Visit https://github.com/bhogancvtc/TDDWithJUnit
- fork the repository there to your own account.
- Ensure you've installed Git to your computer
- Clone your fork of my project to your computer.
The src/Car.java
class contains a simple class representing a car, and
a few methods are already implemented. You'll use test-driven development
to add some new features to the class.
The src/CarTest.java
file contains unit tests for the existing functionality
of the Car
object, but you'll need to add more as you add features.
In Eclipse, you'll import the project.
- From the File menu, choose Import...*.
- Under General, choose Existing Projects Into Workspace
- Select the Root Directory by browsing your file system and selecting the folder you cloned from Github
- The project appears and is checked.
- Do not select the option to copy files to the workspace. You want Eclipse to leave the files in their original location. This way you can easily find them and do your commits. You should use the command line tools for committing your code, not Eclipse's integration..
- Select Finish to import the project.
Once the project's loaded, right-click on the CarTest.java
file and choose Run as JUnit Test
. Every time you make a change to either the test or the Car.java
file, be sure to re-run the test.
-
The
toString()
method on theCar
class isn't properly implemented yet. Implement thetoString()
method ofCar
by using the existing unit test as a guide. Return a string that matches the expectation of the test. -
Implement the
decelerate()
method of Car by writing a unit test first. Ensure that when you call thedecelerate()
method and pass anamount
as its argument, that thespeed
property decreases by that amount. Remember that you should accelerate the car first. The car will not be moving unless you make it move. Do not handle decelerating below 0 yet. -
Write another test that ensures that you can't decelerate more than 0. Then modify the implementation of the
decelerate()
method so that new test passes.
As you develop, follow this approach:
- Create a branch to fix the main test
- Fix the broken test by writing the proper implementation.
- Commit
- Merge the branch back into master.
- Create a new branch for the new feature.
- Write the unit test for the first new feature
- Commit the new test case.
- Implement the passing test.
- Commit.
- Merge branch back to master.
- Repeat steps 5-10 for the other feature.
- Do not write any code unless it's to make a failing test pass.
- Do not write any more of a unit test than is sufficient to fail, and not compiling is failing.
- Do not write more code in the
Car
class than you need to make the current unit test pass.
I will use your Git commits to assess that you have written tests first.
Once you've made the tests pass, consider any refactoring that can be done to improve the code.
Once you're satisfied with your code, push your master branch to Github and then use Github to send me a pull request of your repository for review.
This assessment is worth 40 points.
- You clone this repository and perform the work specified in your own repository.
- You submit a pull request on Github
- Your pull request contains modified versions of the class and the unit test
- The test cases pass.
- You have implemented new methods to make the tests pass.
- Your code is free from errors
- Your code is well formed, correct, and efficient.
- Your Git commit history in your project shows that you developed the tests first. That means you will have multiple commits. You must use Git to demonstrate to me that tests were written before code was implemented.
- Make sure you follow the rules of TDD:
- Do not write any code unless it's to make a failing test pass.
- Do not write any more of a unit test than is sufficient to fail, and not compiling is failing.
- Do not write more code than you need to make the current unit test pass.
- Make sure you follow the rules of TDD: