Skip to content

Commit 15fea4d

Browse files
glennjiHiDtasxatzialkotpIsaacG
authored
Adding a "Test-Driven Development" document (#579)
* Adding a "Test-Driven Development" document Co-authored-by: Jeremy Walker <[email protected]> Co-authored-by: Anastasios Chatzialexiou <[email protected]> Co-authored-by: Victor Goff <[email protected]> Co-authored-by: Isaac Good <[email protected]>
1 parent 9fa53ab commit 15fea4d

File tree

3 files changed

+130
-22
lines changed

3 files changed

+130
-22
lines changed

using/config.json

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
"title": "Solving exercises",
6464
"blurb": "Learn how to solve exercises on Exercism"
6565
},
66+
{
67+
"uuid": "d78582b0-d90a-45a7-a1b4-2e87dac645b1",
68+
"slug": "solving-exercises/tdd",
69+
"path": "using/solving-exercises/tdd.md",
70+
"title": "What is Test-Driven Development?",
71+
"blurb": "Use the TDD methodology and the given test suite to solve exercises"
72+
},
6673
{
6774
"uuid": "7b753e2a-bd68-4d68-bdd8-c356de4342b6",
6875
"slug": "solving-exercises/working-locally",

using/faqs.md

+26-22
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,39 @@ To learn more about what it means for the devil to be in the details, check out
3030

3131
## The Basics
3232

33-
## I'm lost. Where do I go?
33+
### I'm lost. Where do I go?
3434

3535
You're in luck.
3636
Here's a [step-by-step guide][getting-started] to get you started.
3737

3838
If something is still unclear for you or not working then it might be the same for others so we'd appreciate you [letting us know on the forum][forum].
3939

40-
## I get the error "Sorry, we could not authenticate you from GitHub" when trying to log in. What should I do?
40+
### I get the error "Sorry, we could not authenticate you from GitHub" when trying to log in. What should I do?
4141

4242
This means that GitHub isn't willing to verify who you are.
4343
That can be because you chose not to give permission or it might be because your GitHub account is not properly configured.
4444
A common problem is that you haven't verified your email address on GitHub.
4545
You can check that in your [GitHub email settings][email-settings].
4646

47-
## How do I delete my account?
47+
### How do I delete my account?
4848

4949
You can delete your account by following the link at the bottom of your [settings page][settings].
5050
If your issue is with emails and notifications you can adjust that in [your personal preferences][personal-settings].
5151

52-
## How do I unlock exercises?
52+
### What am I supposed to do to solve an exercise?
53+
54+
When you start working on an exercise, you will have a "stub solution" that you need to complete, and you will have a complete test suite that represents the requirements your solution must satisfy.
55+
This development methodology is a form of [Test-Driven Development][tdd].
56+
57+
### How do I unlock exercises?
5358

5459
By default, tracks with Learning Exercises require you to solve Learning Exercises to unlock other exercises (each should take around 5 minutes to solve if you are fluent in a language).
5560
This is called [Learning Mode][learning-mode].
5661

5762
While we recommend using Learning Mode to progress through a track, you could [switch to Practice Mode][switching-modes] to unlock all exercises.
5863
For more information, see [unlocking exercises][unlocking-exercises].
5964

60-
## Why have my unlocked exercises in the old site become locked?
65+
### Why have my unlocked exercises in the old site become locked?
6166

6267
By default, tracks with Learning Exercises require you to solve Learning Exercises to unlock other exercises (each should take around 5 minutes to solve if you are fluent in a language).
6368
This is called [Learning Mode][learning-mode].
@@ -70,24 +75,24 @@ For more information, see [unlocking exercises][unlocking-exercises].
7075

7176
## Exercism Command-line Client
7277

73-
## I can't submit! What should I do?
78+
### I can't submit! What should I do?
7479

7580
The new site has a brand new command-line client, and also needs some extra metadata for your exercise.
7681
Read about how to [upgrade your command-line client and migrate your solutions for the new site][upgrade-cli].
7782

7883
If that doesn't help, or you didn't use the old version of the command-line client, please read through the [command-line client Walkthrough][cli-walkthrough].
7984
If that doesn't help either, [please post on the forum][forum] and we will help you get it sorted out.
8085

81-
## How do I check the version of my command-line client?
86+
### How do I check the version of my command-line client?
8287

8388
The version command `exercism version` outputs the running version of the Exercism command-line client.
8489
By running the version command with the latest flag `exercism version --latest` you can check if there is a newer version available.
8590

86-
## How do I upgrade to the latest version of the command-line client?
91+
### How do I upgrade to the latest version of the command-line client?
8792

8893
The command `exercism upgrade` will upgrade to the latest available version of the command-line client if one is available.
8994

90-
## I get permission denied errors when upgrading! What should I do?
95+
### I get permission denied errors when upgrading! What should I do?
9196

9297
If you are receiving permission denied errors when trying to upgrade the command-line client, chances are the binary was installed via a system package manager (e.g Homebrew) or has been installed into a directory that you no longer have write access to.
9398

@@ -97,36 +102,36 @@ If your command-line client was installed manually, please check the path of the
97102
If so, use the tools provided by your system to change the permissions of the directory to grant write access to your user and trying upgrading again.
98103
If you are not sure if you created the directory, or the returned path is a system path, please use your system tools to uninstall the command-line client and reinstall using the [interactive walkthrough][interactive-walkthrough].
99104

100-
## I get the "16-bit MS-DOS Subsystem" error dialog after upgrading on Windows. What should I do?
105+
### I get the "16-bit MS-DOS Subsystem" error dialog after upgrading on Windows. What should I do?
101106

102107
Prior to version 3.0.5 of the Exercism command-line client, there was a bug in the upgrade command that would replace the command-line client binary file with a single text file causing the "16-bit MS-DOS Subsystem" error.
103108
To resolve this issue remove the corrupt binary and reinstall the command-line client using the [interactive walkthrough][interactive-walkthrough].
104109

105110
## Mentored Mode
106111

107-
## My queue hasn't updated in a while - is there something wrong?
112+
### My queue hasn't updated in a while - is there something wrong?
108113

109114
While wait times can be longer than normal for a number of reasons (number of mentors, time of year), it can also appear that the queue is not updating.
110115
This is not unusual and you should see movement fairly soon.
111116
If you your wait is far longer than the average, refer to [Opening an Issue][opening-an-issue] below.
112117

113-
## How many mentors does my track have? I only see a handful on the website.
118+
### How many mentors does my track have? I only see a handful on the website.
114119

115120
The website only shows mentors who have provided bio information for the website, not the actual number of mentors who are actively reviewing solutions.
116121
Rest assured, there are mentors working through their queues so hang in there!
117122

118-
## I submitted the wrong solution / file. What can I do?
123+
### I submitted the wrong solution / file. What can I do?
119124

120125
On the exercise page in question, navigate to "Your Iterations".
121126
If the unwanted iteration is folded, click the circled arrow.
122127
In the "dots" menu, select "Delete iteration".
123128

124-
## How can I report abuse or examples of bad mentoring?
129+
### How can I report abuse or examples of bad mentoring?
125130

126131
Please check our [Code of Conduct][coc] for more information about our expectations of conduct.
127132
If you would like to report something, please reach out to us at [[email protected]][mail-abuse] and we will try to fix or resolve the issue respecting both you and your privacy.
128133

129-
## Why can't I give feedback on representations?
134+
### Why can't I give feedback on representations?
130135

131136
To give feedback on representations for a track, you need to pass the following three criteria:
132137

@@ -136,24 +141,24 @@ To give feedback on representations for a track, you need to pass the following
136141

137142
## Improving Exercism
138143

139-
## This is great! How do I get involved?
144+
### This is great! How do I get involved?
140145

141146
There are a few different ways - becoming a mentor, managing a language track or reporting (or addressing!) issues on GitHub.
142147
You can see more on the [How to Contribute page][contribute].
143148

144-
## How do new language tracks get added to the site?
149+
### How do new language tracks get added to the site?
145150

146151
A new language track gets created when a member of the community takes the lead on it and becomes a maintainer of the track.
147152
If you'd like to get involved in helping set one up, there are [instructions here][new-language-request].
148153

149-
## Telling us when something is wrong
154+
### Telling us when something is wrong
150155

151156
If you find something that's wrong, please let us know by creating a thread on [the forum][forum].
152157

153158
Before creating a thread, be sure to check for existing discussions.
154159
Try a few different keywords.
155160

156-
## What if my issue is not listed here or on the forum?
161+
### What if my issue is not listed here or on the forum?
157162

158163
If your problem hasn't been resolved or reported, then create a new [forum post][forum].
159164

@@ -164,7 +169,7 @@ Make sure to include the following information:
164169
1. Instructions on how to reproduce the issue
165170
1. If applicable, reference to any related issue using its issue number (formatted like #1203)
166171

167-
## What if there is an issue with language on the website?
172+
### What if there is an issue with language on the website?
168173

169174
If your issue pertains to an exercise in your language track, then please find the correct language track [from this list][from-this-list] and submit an issue there.
170175
Please specify if the issue is with the instructions or something language specific, using the template below.
@@ -190,7 +195,6 @@ If you have spotted a typo or if you have a suggestion for clearer language or i
190195
[kytrinyx]: https://exercism.github.io/kytrinyx/
191196
[languages]: https://github.com/search?q=topic%3Aexercism-track+org%3Aexercism&type=Repositories
192197
[learning-mode]: /docs/building/product/unlocking-exercises#h-learning-mode-vs-practice-mode
193-
194198
[mail-abuse]: mailto:[email protected]?subject=%5BCoC%5D]
195199
[forum]: https://forum.exercism.org/
196200
[new-language-request]: https://github.com/exercism/generic-track/blob/main/README.md
@@ -202,4 +206,4 @@ If you have spotted a typo or if you have a suggestion for clearer language or i
202206
[switching-modes]: /docs/building/product/unlocking-exercises#h-switching-modes
203207
[unlocking-exercises]: /docs/building/product/unlocking-exercises
204208
[upgrade-cli]: https://github.com/exercism/website-copy/blob/main/pages/cli_v1_to_v2.md
205-
[website-copy]: https://github.com/exercism/website-copy/issues
209+
[tdd]: https://exercism.org/docs/using/solving-exercises/tdd

using/solving-exercises/tdd.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Test-Driven Development (TDD)
2+
3+
Test-Driven Development (sometimes called Test-First Development or Test-Driven Design) is the practice of writing the unit tests first, before you write a single line of implementation code.
4+
5+
## On Exercism, the tests _are_ the requirements!
6+
7+
All Practice Exercises you work on (those ones that don't teach you a new concept) will have some instructions describing in general terms what you need to do.
8+
By design, these instructions do not account for programming-language-specific implementation details because they are shared by all of Exercism's 70+ language tracks.
9+
Some language tracks will append more specific details for you, but not all of them do.
10+
11+
When you start working on a Practice Exercise, give the instructions a careful read.
12+
They will give you a broad overview of how you go about implementing a solution.
13+
But you will have to read the _tests_ to understand the full and exact requirements:
14+
15+
- Must the result be a particular kind of data structure?
16+
- Must the result be sorted in some order?
17+
- How are you expected to handle exceptions? And so on.
18+
19+
You have solved an exercise when all the provided tests run and pass.
20+
In other words, your solution is not just an interpretation of the instructions that "looks right", your solution is a program that _satisfies the given tests_.
21+
**The tests represent the complete requirements for the exercise.**
22+
23+
## How does Exercism apply TDD?
24+
25+
We've done the work of writing a unit test suite for you.
26+
Your goal is to write a solution that contains just enough code to make all those unit tests pass.
27+
28+
Keep this in mind: the TDD approach will help you get to the solution, but you don't need to stop there.
29+
If you want to extend your solution beyond the requirements, you are welcome to do so.
30+
Should you choose to work with a mentor (and we encourage you to do that once you get the tests passing), they can help you refactor and refine your initial implementation, or even propose new unit tests.
31+
32+
## Working in the online editor
33+
34+
When you're working in the code editor on Exercism's website, you can read the tests but you are not able to edit them.
35+
All tests will be executed each time you run them, regardless of any "skip" mechanisms noted in the test file.
36+
37+
When there are multiple tests that fail, the website initially only displays the results of the first failure.
38+
You can click on other failures to expand them, too!
39+
Sometimes the first result may not be the most informative.
40+
41+
Don't be discouraged by a large number of failing tests.
42+
Focus on making them pass one-by-one.
43+
44+
## Working locally
45+
46+
Many tracks use "skipped" tests in their test files.
47+
Initially, only the first test is "active" and the remaining are inactive (how this happens varies by track).
48+
When you run the test suite in your environment, only the first test runs.
49+
We do this to encourage you to follow this workflow:
50+
51+
1. Before adding any new code, run the test suite: you should see a failing test.
52+
1. Add _just enough_ code to pass the test.
53+
1. Run the test suite.
54+
1. If the test still fails, repeat step 2.
55+
1. Once the test passes, refactor your code as desired, ensuring all active tests still pass.
56+
Refactoring might include:
57+
- removing any duplicated code,
58+
- splitting long functions into smaller ones,
59+
- adding comments, etc.
60+
1. "Unskip" the next test and repeat from step 1.
61+
62+
Repeat these steps until you have unskipped all the tests.
63+
Once all the tests are passing, congratulations, you have solved the exercise!
64+
65+
Exactly how tests are "unskipped" (or activated) depends on the track.
66+
For some tracks, it might be commenting or removing an annotation.
67+
For some tracks, it might be changing an attribute from true to false.
68+
Take the time to read [the documentation for your track][track-docs]; it will explain these details.
69+
70+
For tracks that don't skip the tests, applying this workflow may be as straightforward as commenting out the tests and uncommenting them one-by-one.
71+
72+
## Rationale for Test-Driven Development
73+
74+
While it may seem like "putting the cart before the horse", there are several good reasons why you might want to write unit tests before writing the implementation code.
75+
76+
1. Design.
77+
It forces you to think first about your program's [interface][api] (how it exposes its functionality to the world), instead of jumping straight into how you will implement the code.
78+
Having a well-designed (and testable!) interface is often more important than having an efficient implementation.
79+
80+
1. Discipline.
81+
Writing tests is often seen as a chore or an afterthought; writing the tests _first_ guarantees that at the end of the day you will have written enough unit tests to cover most or all of your code's functionality (rather than possibly never getting around to it).
82+
83+
1. Less Work.
84+
If you apply a tight cycle of write one test, then write the code to implement that test, then write the next test, your code ends up growing organically.
85+
This often (though not always) leads to less wasted effort; you end up writing all the code you need, and none of the code you don't need.
86+
87+
## Further reading
88+
89+
- [About Test-First Teaching][test-first] at the archived TestFirst\.org site.
90+
- [Test-driven development][tdd-wiki] at Wikipedia.
91+
- [Test Driven Development][tdd-python] on the Python track.
92+
93+
[track-docs]: https://exercism.org/docs/tracks
94+
[test-first]: https://web.archive.org/web/20220918221108/http://testfirst.org/about
95+
[tdd-wiki]: https://en.wikipedia.org/wiki/Test-driven_development
96+
[tdd-python]: https://exercism.org/docs/tracks/python/test-driven-development
97+
[api]: https://en.wikipedia.org/wiki/API

0 commit comments

Comments
 (0)