Challenge: Test Using Best Practices

Apply what you have learnt about the foundations of unit testing by completing the project in this lesson.

Introduction

In this project, you will write a unit test that tests the behavior of a class that models banking transactions. To frame your state of thinking in designing the unit tests, we’ve provided an assessment rubric. It will help indicate whether the principles that were taught in this section have been considered and applied.

Self assessment rubric

I have… Emergent Satisfactory Excellent
Excluded control logic in my tests There was extensive use of control logic in tests. There was limited use of control logic in tests. There was no use of control logic in tests.
Chosen a concise and consistent naming convention Inconsistent, verbose, and non-descriptive naming was used. A somewhat concise and consistent naming convention was used. A concise and fully consistent naming convention was used.
Ensured maximum test coverage Not all methods were covered/tested. All methods were covered/tested but some didn’t test all possible inputs. All methods and all input behavior was tested.
Limited my tests to non-trivial code Test cases were developed for all trivial code. Some test cases were developed for trivial code. No test cases were developed for trivial code.
Striven for one assertion per test All test cases have more than one assertion. Some test cases have more than one assertion. Each test case has one assertion.
Utilized code coverage tools No code coverage exercise was performed. Code coverage was performed. In the event, branch coverage was shown to be below 100%, no corrective action was taken. Tests were checked with a code coverage tool and had a 100% branch coverage.

Project code

In your own environment, copy the following application code and write unit tests that fully test this application code. You may also use the widget below to write and run your tests:

Get hands-on with 1200+ tech skills courses.