You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
7This "unit tests are the contract" point is a critical one I'm not sure I've seen made explicitly enough elsewhere.Charles Duffy– Charles Duffy2023-06-15 02:27:20 +00:00Commented Jun 15, 2023 at 2:27
-
2"I've almost never had to make a mock of an interface for a unit test." You must have a different concept of unit test than I do. If you test a "unit" (a class, a module, some small-ish part of code) in isolation (because this is what a unit test does: It disregards the rest of the software): Then you have to, by definition, replace -- mock, stub, whatever -- the parts of the software with which the unit is interfacing.Peter - Reinstate Monica– Peter - Reinstate Monica2023-06-15 12:31:58 +00:00Commented Jun 15, 2023 at 12:31
-
@Peter: In many cases, units can be designed with minimal dependencies, so that there are few if any other pieces of code that need to be faked. This is why one of my bullet points was "To discourage unnecessary coupling." The anticipated pain of writing unit tests for code that has lots of coupling would hopefully guide the design towards more isolated, standalone units. Also, I believe that, if unit Foo depends on some specialty container and that container is itself thoroughly unit tested, then there's no point in mocking the container when testing Foo.Adrian McCarthy– Adrian McCarthy2023-06-15 16:14:37 +00:00Commented Jun 15, 2023 at 16:14
-
1@Corrodias: Absolutely. Any object that acts as an interface to a database session, network connection, clock, etc., probably needs a mock or fake of that thing. But there should be very few of those. I've seen too many designs where every unit that processes data is directly dependent on the data source and thus all of those units need dependency injection so the test can pass in a fake/mock. In nearly all cases, those units should just accept data directly from the caller.Adrian McCarthy– Adrian McCarthy2023-06-15 18:44:54 +00:00Commented Jun 15, 2023 at 18:44
-
4"Unit tests are the contract" ... In the case of changed requirement : first change the test. Run the testsuite : the unmodified code should fail the test. Then you are in a strong position to modify the code to implement the changed requirement.user_1818839– user_18188392023-06-15 21:40:30 +00:00Commented Jun 15, 2023 at 21:40
|
Show 1 more comment
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. design-patterns), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you