Activity: Test-Driven Development
This activity is intended to supplement the CS4530 lecture on test-driven development. You will need to have already completed the development environment setup for the class.
Changelog
- Changed “Document these as comments” to “Document these (in the same format as before)” in Step 7. Moved the “these tests will fail” comment to Step 8, where it makes more sense.
Steps
- Get the starter code by cloning the
transcript-service-m02repository from GitHub - Run
npm installinside the directory that is created when you unzip the download. -
Check that every member of the group can run
npx vitest --run src/types.spec.tsand see one failing and one passing test.
-
Check that every member of the group can run
npx vitest --run src/transcript.service.spec.tsand see five passing tests.
-
Check that every member of the group can run
npm run testto run Vitest on all the test files simultaneously and see six passing tests and one failing test.
-
Check that every member of your group can see the ESLint error in
src/transcript.service.ts. Discuss how to fix the error. -
Write down two testable behaviors for the
addGradefunction corresponding to the condition of satisfaction that “the user can add a new grade for an existing student.” These should be written asit("<testable beahvior>", () => {})insrc/transcript.service.spec.ts. -
Come up with at least two ways in which the
addGradefunction isn’t completely specified by the conditions of satisfaction given in lecture. Document these (in the same format as before) insrc/transcript.service.spec.ts. -
Add Vitest tests to your testable behaviors in
src/transcript.service.spec.ts. (There should be at least four new tests foraddGradeat this point. These tests will fail, becauseaddGradeis not implemented. You are not required to implement or submitaddGrade.) - When you are done, submit the modified
src/transcript.service.spec.tsfile as required by your instructor.
Grading Rubric:
Grading will be done via “specification grading”.
There are only two non-zero grades: Satisfactory (10 points), and Minimal (5 points).
To obtain a grade of Satisfactory, you must deliver all of the requirements listed in the instructions.
To obtain a grade of Minimal, you must have at least two meaningful tests for addGrade in src/transcript.service.spec.ts.
Grading will be manual; the TAs will look at your solution; they may or may not run them.