Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
jen20
9 months ago
|
parent
|
context
|
favorite
| on:
Dependency injection frameworks add confusion
If you only have one implementation, why do you even have an interface?
rawling
9 months ago
[–]
So I can mock it out for unit tests.
jen20
9 months ago
|
parent
[–]
Then you have two implementations…
orphea
9 months ago
|
root
|
parent
|
next
[–]
You don't necessarily need to implement interfaces [in your code] to stub them in unit tests:
var calculator = Substitute.For<ICalculator>();
jen20
9 months ago
|
root
|
parent
|
next
[–]
If you’re doing that, you may as just mock your concrete class. Mockito supports this in Java. Perhaps this is needed in C#?
wordofx
9 months ago
|
root
|
parent
|
next
[–]
Java is virtual by default. C# is not. You could mark every single method virtual and mock it like Java. But it’s easier to define a contract and mock that.
rawling
9 months ago
|
root
|
parent
|
prev
|
next
[–]
Not one that shows up when I hit "go to implementation".
wordofx
9 months ago
|
root
|
parent
|
prev
[–]
LOL ok so you’ve never used C#
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: