Character copier
We use this kata to demonstrate the concepts of test doubles.
Overview
The character copier is a simple class that reads characters from a source and copies them to a destination one character at a time.
When the Copy() method is called on the copier, it should read characters from the source and copy them to the destination until the source returns a newline (ā\nā). Implement the character copier using test doubles for the source and the destination as follows.
Start from these definitions:
Objectives
Write a stub for source and a spy for destination in your test project.
Repeat the kata but use a mocking framework to create mocks for source and destination.
What differences did you find between the two approaches? Which is simpler? What are the pros and cons of each approach?
Examples
Source characters: "abc\n"
(string) or {'a', 'b', 'c', '\n'}
(array of char)
Copier.Copy();
Destination characters: "abc"
(string) or {'a', 'b', 'c'}
(array of char)
Last updated