Welcome Guest, Not a member yet? Register   Sign In
Unit Testing
#9

(This post was last modified: 03-15-2016, 10:29 AM by kilishan. Edit Reason: Showing reasoning )

(03-15-2016, 07:29 AM)Narf Wrote: And a primary goal of unit testing is pinpointing the exact unit of code that isn't functioning properly.

Yes, it makes for harder to maintain tests and yes - in most cases (relatively simple applications) testing only public APIs is completely sufficient. But that doesn't mean the opposite is evil.

You're advocating black-box testing and equating it with all of testing, which is not correct. Smile

Didn't mean to imply was evil and even said was to be avoided in general, but that there were cases.

Either way, it's my current advice base on current knowledge and past experiences. Everyone is free to take it or leave it. Smile

EDIT: Since there are debates about this kind of thing all over the internet, and I have zero desire to get caught up in one of those here, I'll just present my thoughts and understanding of the matter in case it helps someone out. If it doesn't, or goes against the way you like to use it and/or think about, that's cool, tool.

I think the biggest issue here is the term, unit. That seems to be where a lot of the differences in opinion come from. When talking about unit testing, you have to decide what unit you're concerned with testing. This could be the entire class, since, if well implemented, it's a unit on it's own, like a blog post, or a URL. Most of the time, for me, that is the unit that I'm concerned about. The public API, or the methods that other classes will be interacting with, are what's important, so that's what I test against. As stated earlier, this makes it easy to refactor what happens behind the public API and having your tests help confirm things are still working as desired.

Other times, the unit that you might be concerned with is a specific method, and this might be private. That's also perfectly valid, and I do feel both uses work together and complement each other. One example on a recent project were some methods that were used for normalizing data for a UK-based company. It was very important to ensure that each of those normalization routines (phone, postal code, etc), worked correctly on their own. So we tested those private methods extensively.

Different people, teams, and projects have different needs and/or ways of thinking about it. As far as I'm concerned, they're often all correct for that situation. So - use what makes sense to you, as long as you've thought it through and have reasons for it.
Reply


Messages In This Thread
Unit Testing - by acsv - 03-14-2016, 02:38 PM
RE: Unit Testing - by kilishan - 03-14-2016, 07:25 PM
RE: Unit Testing - by acsv - 03-14-2016, 09:24 PM
RE: Unit Testing - by Narf - 03-15-2016, 06:24 AM
RE: Unit Testing - by albertleao - 03-14-2016, 09:05 PM
RE: Unit Testing - by kenjis - 03-15-2016, 05:52 AM
RE: Unit Testing - by kilishan - 03-15-2016, 06:46 AM
RE: Unit Testing - by Narf - 03-15-2016, 07:29 AM
RE: Unit Testing - by kilishan - 03-15-2016, 10:09 AM



Theme © iAndrew 2016 - Forum software by © MyBB