Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you only have one implementation, why do you even have an interface?


So I can mock it out for unit tests.


Then you have two implementations…


You don't necessarily need to implement interfaces [in your code] to stub them in unit tests:

    var calculator = Substitute.For<ICalculator>();


If you’re doing that, you may as just mock your concrete class. Mockito supports this in Java. Perhaps this is needed in C#?


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.


Not one that shows up when I hit "go to implementation".


LOL ok so you’ve never used C#




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: