Skip to content

Commit d72dace

Browse files
authored
Merge pull request sarven#2 from bueltge/main
Small grammar corrections.
2 parents a8f422c + 80b161c commit d72dace

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## Introduction
44

5-
In these times the benefits of writing unit tests are huge.
5+
In these times, the benefits of writing unit tests are huge.
66
I think that most of the recently started projects contain any unit tests.
77
In enterprise applications with a lot of business logic, unit tests are the most important tests,
88
because they are fast and can us instantly assure that our implementation is correct.
9-
However, I often see a problem with good tests in projects, though the benefits of these tests are only huge when you have good unit tests.
9+
However, I often see a problem with good tests in projects, though these tests' benefits are only huge when you have good unit tests.
1010
So in these examples, I will try to share some tips on what to do to write good unit tests.
1111

1212
## Table of Contents
@@ -42,8 +42,6 @@ So in these examples, I will try to share some tips on what to do to write good
4242
18. [100% Test Coverage shouldn't be the goal](#100-test-coverage-shouldnt-be-the-goal)
4343
19. [Recommended books](#recommended-books)
4444

45-
## Introduction
46-
4745
## Test doubles
4846

4947
Test doubles are fake dependencies used in tests.
@@ -171,7 +169,7 @@ $mailer
171169
```
172170

173171
:exclamation:
174-
To verify incoming interactions use a stub, but to verify outcoming interactions use a mock.
172+
To verify incoming interactions, use a stub, but to verify outcoming interactions, use a mock.
175173
More: [Mock vs Stub](#mock-vs-stub)
176174

177175
## Naming
@@ -254,9 +252,9 @@ If your code is just a utility one it's less important.
254252
If there is a project with complex domain logic, this logic must be very clear for everyone,
255253
so then tests describe domain details without technical keywords, and you can talk with a business in a language like in these tests.
256254

257-
All code that is related to the domain should be free from technical details. A non-programmer won't be read these tests,
258-
but if you want to talk about the domain these tests will be useful to know what this domain does.
259-
There will be a description without technical details e.g. returns null, throws an exception, etc.
255+
All code that is related to the domain should be free from technical details. A non-programmer won't be read these tests.
256+
If you want to talk about the domain these tests will be useful to know what this domain does.
257+
There will be a description without technical details e.g., returns null, throws an exception, etc.
260258
This kind of information has nothing to do with the domain, so we shouldn't use these keywords.
261259

262260

@@ -339,10 +337,9 @@ final class ExampleTest
339337

340338
## Parameterized test
341339

342-
The parameterized test is a good option to test the SUT with a lot of parameters without repeating the code.
340+
The parameterized test is a good option to test the SUT with many parameters without repeating the code.
343341

344-
:thumbsdown: This kind of test is less readable. To increase the readability a little, negative and positive examples should be
345-
split up to different tests.
342+
:thumbsdown: This kind of test is less readable. To increase the readability a little, negative and positive examples should be split up to different tests.
346343

347344
```php
348345
final class ExampleTest extends TestCase
@@ -453,7 +450,7 @@ final class TestExample extends TestCase
453450

454451
[TODO]
455452

456-
## Mock vs Stub
453+
## Mock vs. Stub
457454

458455
Example:
459456
```php
@@ -675,7 +672,7 @@ an infrastructure code related to a file system.**
675672

676673
:heavy_check_mark: Good:
677674

678-
Like in the functional architecture we need to separate a code that has side effects and code which contains only logic.
675+
Like in functional architecture, we need to separate a code with side effects and code that contains only logic.
679676

680677
```php
681678
final class NameParser
@@ -758,7 +755,7 @@ final class ValidUnitExampleTest extends TestCase
758755
}
759756
```
760757

761-
## Observable behavior vs implementation details
758+
## Observable behavior vs. implementation details
762759

763760
:x: Bad:
764761

@@ -957,8 +954,8 @@ final class ValidTestExample extends TestCase
957954
```
958955

959956
:information_source: The first subscription model has a bad design. To invoke one business operation you need to call three methods. Also using getters to verify operation is not a good practice.
960-
In this case, it's skipped checking a change of modifiedAt, probably setting specific modifiedAt during a renew operation can be tested with an expiration business operation. The getter for modifiedAt is not required.
961-
Of course, there are cases where finding the possibility to avoid getters provided only for tests will be very hard, but always we should try to not introduce them.
957+
In this case, it's skipped checking a change of `modifiedAt`, probably setting specific `modifiedAt` during a renew operation can be tested with an expiration business operation. The getter for `modifiedAt` is not required.
958+
Of course, there are cases where finding the possibility to avoid getters provided only for tests will be very hard, but always we should try not to introduce them.
962959

963960
## Unit of behavior
964961

@@ -1213,7 +1210,7 @@ class SubscriptionTest extends TestCase
12131210
}
12141211
```
12151212

1216-
:exclamation: **Do not write code 1:1, 1 class : 1 test. It leads to fragile tests which make that refactoring is very hard.**
1213+
:exclamation: **Do not write code 1:1, 1 class : 1 test. It leads to fragile tests which make that refactoring is tough.**
12171214

12181215
:heavy_check_mark: Good:
12191216

@@ -1689,7 +1686,7 @@ final class TestUserRepository extends TestCase
16891686
}
16901687
```
16911688

1692-
:exclamation: Testing repositories in that way leads to fragile tests and then refactoring is very hard. To test repositories write integration tests.
1689+
:exclamation: Testing repositories in that way leads to fragile tests and then refactoring is tough. To test repositories write integration tests.
16931690

16941691
## Test fixtures
16951692

@@ -1891,8 +1888,7 @@ final class ValidTest extends TestCase
18911888
```
18921889

18931890
:exclamation: Adding additional production code (e.g. getter getCustomerType()) only to verify the state in tests is a bad practice.
1894-
It should be verified by another domain significant value (in this case getPercentageDiscount()). Of course, sometimes it can be very hard
1895-
to find another way to verify the operation, and we can be forced to add additional production code to verify correctness in tests, but we should try to avoid that.
1891+
It should be verified by another domain significant value (in this case getPercentageDiscount()). Of course, sometimes it can be tough to find another way to verify the operation, and we can be forced to add additional production code to verify correctness in tests, but we should try to avoid that.
18961892

18971893
### Leaking domain details
18981894

@@ -2210,7 +2206,7 @@ final class ValidTest extends TestCase
22102206

22112207
### Time as a volatile dependency
22122208

2213-
:information_source: The time is a volatile dependency because is non-deterministic, each invocation returns a different result.
2209+
:information_source: The time is a volatile dependency because it is non-deterministic. Each invocation returns a different result.
22142210

22152211
:x: Bad:
22162212

0 commit comments

Comments
 (0)