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.
-
8I believe the point of mocking dependencies is to ensure that if the test fails, only the subject of the test could be the cause for the failure. If you're testing class A and using a real instance of B instead of mocking IB, if B has a bug in it, your A tests will fail. That's why I mock everything, until you reach integration tests, where you want to test all your functionality together.Callum Bradbury– Callum Bradbury2016-10-17 13:28:57 +00:00Commented Oct 17, 2016 at 13:28
-
4There's only one problem with that argument, @Callum. When you're writing mock-heavy unit tests and they fail, what's the first thing you suspect? You blame the mock first, then the UUT. Having multiple causes of failure is unavoidable. Mocks aren't chosen because they are magically error-free. They are chosen because they break the dependency chain, are easier to introspect, and sometimes execute faster.Karl Bielefeldt– Karl Bielefeldt2016-10-17 17:53:56 +00:00Commented Oct 17, 2016 at 17:53
-
@David thanks for your answer. In response to your answer, I have updated my question to be more clear. When I said mocking, I meant all kinds of mocking/stubbing, as compared to using real implementation.Phuong Nguyen– Phuong Nguyen2016-10-18 01:38:42 +00:00Commented Oct 18, 2016 at 1:38
-
4@David I have read the 2 links mentioned in your answer: the first article, actually is actually pointing to another article which is the current approach that I'm using (docs.google.com/file/d/0B_zwMmx15DL8NDdVT2gxLWk1OHc/edit?pli=1). In the second article, the author admits he used integration test to avoid using mock. That leads me back to your conclusion on definition of unit test. To me, a unit test should test smallest possible unit of code, which in a OO project, is normally a method or a class. A unit test that tests nearly the whole system is beyond my imaginationPhuong Nguyen– Phuong Nguyen2016-10-18 01:41:15 +00:00Commented Oct 18, 2016 at 1:41
-
1@DavidArno The point of unit tests is to test an individual piece of code, if there's a bug in B your unit tests for B should find them. If there's a bug in B and your tests in A find them, that's going to cause confusion and false negatives. The key to unit tests is that they test very specific things, and are free from outside influences, if you allow A to use B in tests you're muddying the waters, it's better to have individual tests for each class, so that you can easily identify the reason for failure, and come up with a solution.Callum Bradbury– Callum Bradbury2016-10-19 11:15:13 +00:00Commented Oct 19, 2016 at 11:15
|
Show 6 more comments
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