The goal of this assignment is to reinforce the importance of unit testing in Java using JUnit. You will design and implement a suite of unit tests for the train simulation we wrote A4: Chugging Along. Your A4 solution consisted of the following classes:
Car: Represents a train car.
Engine: Represents the train’s engine.
Passenger: Represents passengers who board and leave the train.
Train: Represents an entire train with one or more cars.
In this assignment, you will write at least 10 unit tests that verify the functionality and correctness of each of these classes.
- Fork the the repository for CSC120-A6, and clone it to your local machine.
- Add your
Car.java,Engine.java,Passenger.java, andTrain.javato your forked repository and commit your changes. - Analyze the functionality of the classes contained in those files.
- Enable Java tests using the
jUnittesting framework.
Write your jUnit tests inside TrainTest.java, using assertions to validate expected outputs. Below you'll find a list of key methods in each class that should be tested:
- Verify that the
Engineconstructor initializes correctly with the givenFuelTypeand fuel level. - Test the
go()method to ensure that fuel consumption reduces the fuel level correctly.
- Ensure that adding a
Passengerincreases the passenger count. - Check that removing a
Passengerdecreases the count and doesn't go negative.
- Test that a
Passengercan successfully board aCar. - Ensure that a
Passengercannot board a fullCar.
- Verify that a
Traininitializes correctly with a given number ofCars. - Ensure the
Train’s totalPassengercount updates asPassengers board and leave. - Check that the
getCar(int i)method returns the expectedCar. - Test the
printManifest()method to ensure it iterates through theTrainsCars correctly.
These are only a starting point; you are welcome to write additional tests if you would like.
As before, all the files necessary for this assignment are contained within this repository. When you submit, please remember to include:
- all files necessary to compile your program
reflection.mdcontaining your reflections and notesrubric.mdwhere you document which elements of the assignment you have attempted and/or completed