DEV Community

Discussion on: Test Contravariance - Who Understands It And Can Provide an Example?

Collapse
 
bhserna profile image
Benito Serna • Edited

What I understand is that you should design your tests to be another client for your code... so if in your production code you have an explicit API to use for your client... you should also use that API for your tests...

I prepared an small example with the TicTacToe game. You can find it on gist.github.com/bhserna/882d5101bd......

In particular look how I used the internal class Game::Board but I don't have a test for that class, because its behavior is already covered in the tests for the game.

This is a small example, but I hope you can find it useful =)

Collapse
 
scotthannen profile image
Scott Hannen

Hi,

I appreciate the example, but could you just link to the source code instead of posting it? It's about seven pages of scrolling and I'm concerned that it might stifle additional responses.

Thanks!

Collapse
 
bhserna profile image
Benito Serna

Ready! I just remove the code from the post... It would be nice to see an example from you also =)

Thread Thread
 
scotthannen profile image
Scott Hannen

Thanks! I don't have one. I'm going to go back and read Robert Martin's post all over again.