Skip to content

Commit fdbac75

Browse files
committed
docs(readme): add tests and mothers in idiomatic section
1 parent e1312fe commit fdbac75

File tree

1 file changed

+59
-5
lines changed

1 file changed

+59
-5
lines changed

README.md

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,24 +367,27 @@ It is a monolith where CRUD operations can be performed from different presentat
367367

368368
### Idiomatic
369369

370+
> [!TIP]
371+
> [VSCode Snippets](.vscode/vs.code-snippets) available (We can see them in IntelliSense (`Ctrl+Space`) or simply by typing `go-`).
372+
370373
- **Domain**
371-
- `errors.New*()`, `errors.BubbleUp()` & `errors.Panic()`
374+
- `errors.New[...]()`, `errors.BubbleUp()` & `errors.Panic()`
372375
- Only in the `Domain` layer and in the `*_test.go` files can we throw `errors.Panic()`.
373376
- **Infrastructure**
374377
- `New*()`, `Open()` & `Close()`
375378
- `session`
376-
- `errors.New*()` & `errors.BubbleUp()`
379+
- `errors.New[...]()` & `errors.BubbleUp()`
377380
- **Application**
378381
- `Run()`, `Handle()` & `On()`
379-
- `errors.New*()` & `errors.BubbleUp()`
382+
- `errors.New[...]()` & `errors.BubbleUp()`
380383
- **Presentation**
381384
- **Modules**
382385
- `Start()` & `Stop()`
383386
- `errors.BubbleUp()`
384387
- **Services / Apps**
385388
- `Init()`, `Up()` & `Down()`
386389
- `log.[Wrap]()`
387-
- `errors.New*()` & `errors.BubbleUp()`
390+
- `errors.New[...]()` & `errors.BubbleUp()`
388391
- In `Apps` we will handle `Bubble Errors`.
389392
- **Main**
390393
- `log.Fatal()` & `log.[Wrap]()`
@@ -399,6 +402,57 @@ It is a monolith where CRUD operations can be performed from different presentat
399402
- **Blocks**
400403
- `const`, `var`, & `type`
401404
- We will group only those that are declared on a single line.
405+
- **Tests**
406+
- **Subject/System/State Under Test (SUT)**
407+
- The `SUT` will only be explicitly defined within the "suite (in the `s.SUT` field)" in those tests that cover several entities, such as "handlers/consumers, use cases, roles...".
408+
- When testing only "functions and/or methods", it is not necessary to define an explicit `SUT` within the "suite (in the `s.SUT` field)", since the name of the "test cases" will indicate which `SUT` that specific case belongs to.
409+
- **Suite**
410+
- `<SUT>TestSuite`
411+
- The name of the `<SUT>` can be that of the package, function, or type.
412+
- `<SUT>Suite`
413+
- When shared to test different implementations of the same `interface`.
414+
- **Cases**
415+
- **Happy Path**
416+
- `Test<Function/Method>()`
417+
- `Test<Function/Method><With/Without>*()`
418+
- **Corner Case**
419+
- `Test<Function/Method><Err/Panic>*`
420+
- The semantics of the message and/or the words used after `<Err/Panic>` should only come from the error that is checked in the "test case".
421+
- We will only check for errors originating in the function or method being tested.
422+
- With "Generic[...] Functions".
423+
- `Test<Function>*()`
424+
- `Test<Function>*<With/Without>*()`
425+
- `Test<Function>*<Err/Panic>*()`
426+
- **Sentinel**
427+
- They are used to "compare" already defined values against "hardcoded" values to ensure their integrity.
428+
- **Exceptions**
429+
- In the "errors" package, there may be exceptions in the names of the "test cases" to avoid confusion.
430+
- **Mothers**
431+
- **Subject Under Test (SUT)**
432+
- The `SUT` always refers to the "value (subject)" used within the method, whether to return an instance or generate an error.
433+
- **Factory**
434+
- **Valid** (used in **"Happy paths"**)
435+
- `<SUT>Valid*()`
436+
- **Invalid** (used in **"Corner Cases"**)
437+
- `<SUT>Invalid*()`
438+
- When it is necessary to define parameters in the method we use `With` to describe them, but `With` is not necessary in methods with a single "...variadic parameter".
439+
- `<SUT>ValidWith*()`
440+
- `<SUT>InvalidWith*()`
441+
- **Wrap**
442+
- These methods are only used to avoid handling error comparisons in "test cases".
443+
- `<SUT>New()`
444+
- `<SUT>Copy()`
445+
- `<SUT>Replace()`
446+
- With the exception of `Invalid`, all other methods that generate an error must throw a `panic()` and should never be ignored using `_`.
447+
- There will only be one `Mother (mother.go)` per package.
448+
449+
### Snippets
450+
451+
1. Check
452+
1. Spelling
453+
2. Format
454+
3. Jumps
455+
2. Test
402456
403457
### ...`v0` > `dev0.1.0` > `ci/dev0.1.0` > `main` > `v0`...
404458
@@ -655,7 +709,7 @@ curl -sSfLO https://github.com/bastean/codexgo/archive/refs/heads/main.zip \
655709
```
656710
657711
- Social preview
658-
- Upload an image
712+
- Upload an image...
659713
660714
#### Actions
661715

0 commit comments

Comments
 (0)