Tagged Questions
8
votes
2answers
463 views
Unit Testing: “It's a code smell if you're refactoring and there are no collaborators”?
I'm reading The Art of Unit Testing by Roy Osherove. I'm at section 7.2 Writing maintainable tests where the author has this note about code smell:
NOTE: When you refactor internal state to be ...
1
vote
2answers
250 views
Unit Tests code duplication?
How can I avoid code duplication in unit tests?
Using Java and JUnit suppose I have something like this:
public interface Arithmetic<T> {
public T add(T a, T b);
public T sub(T a, T ...
1
vote
2answers
56 views
Should Multiple Data Items be in Multi Unit Test Methods?
I often want to have the same unit test applied to data multiple items that are roughly equivalent (two non-empty strings). Currently I implement these in multiple unit test methods, with names like ...
7
votes
5answers
432 views
Writing Testable Code vs Avoiding Speculative Generality
I was reading some blog posts this morning, and stumbled across this one:
If the only class that ever implements the Customer interface is
CustomerImpl, you don't really have polymorphism and ...
6
votes
3answers
387 views
Is having a switch to turn mocking on or off a code smell?
I have a method that looks like this:
def foobar(mock=False, **kwargs):
# ... snipped
foobar actually makes several calls to Amazon S3 and returns a composed result.
In order to make this ...
43
votes
12answers
2k views
If your unit test code “smells” does it really matter?
Usually I just throw my unit tests together using copy and paste and all kind of other bad practices. The unit tests usually end up looking quite ugly, they're full of "code smell," but does this ...
2
votes
2answers
137 views
Unit testing code paths
When unit testing using expectations, you define a set of method calls and corresponding results for those calls. These define the path through the method that you want to test.
I have read that unit ...