r/programming • • Apr 29 '14

Programming Sucks

http://stilldrinking.org/programming-sucks
3.9k Upvotes

1.1k comments sorted by

View all comments

Show parent comment

2

u/Stormflux Apr 30 '14 edited Apr 30 '14

My biggest barrier to automated testing is that 90% of my code is either interacting with a database or passing views / json to a web browser.

At the Controller level, it's kind of pointless to test that "return View("Index")" returns a view called Index. We already know that's going to work, but now we have the added overhead that if we ever change it to "return View("Home"), the test is going to complain.

And at the Database level, the part that's going to go wrong (the SQL / Entity Framework statements) is abstracted away by Mocks and Fakes. So... what am I supposed to do?

3

u/UsingYourWifi Apr 30 '14

So... what would you say your code does here?

Is there any behavior that can be tested?

2

u/Stormflux Apr 30 '14

It talks to the database to the controller doesn't have to. It has people skills!!

2

u/dnew Apr 30 '14

The right way to do mocks is to test two levels down from what you're doing.

The JS tests that invoke the web server don't mock out the web server; they mock out the database.

The server tests don't mock out the database; they mock out the underlying file system.

If you're mocking what's directly underneath you, you're not going to get any benefit.