How many tests?
Here is an interesting question, how many tests do you need for the following method?
///<summary> ///Get the latest published webcast ///</summary> public Webcast GetLatest();
Here is how the Webcast entity looks like:
None, good programmers write perfect code first time.
Enough to ensure that you are correctly getting the Webcast that has the most recent PublishDate, not simply the one that happens to have been most recently added to wherever the Webcasts are stored. Maybe make sure it works when there are no Webcasts stored, when there is one Webcast, and when there are multiple Webcasts.
Here's a question -- what if the PublishDate is in the future? Should it be returned? If not, that's another test.
What happens if two Webcasts have the same PublishDate? Which one is "the latest"? Whatever the answer, there's a scenario for another test.
@JacobM - Yet another case is what should GetLatest() do if (!PublishDate.HasValue)?
It's a trick question. It takes as many tests as is necessary to drive out the design.
I'd probably start with something like:
public void GetLatestWebcastCallsGetLatestOfDAO();
since we'll have some sort of data access. I'd also likely have tests in place for equality and hashCode of the Webcast object itself (though it could be abstracted away).
Then, for the DAO, I'd likely have tests in place to make sure that we were calling the data layer correctly, probably by using an in-memory DB. Then we'd need integration tests to make sure everything was working correctly.
The whole nullable DateTime seems interesting - but it also seems like it would be abstracted by the data access layer. If we store the webcasts in a file system, then we have at least the create or last modified date. If they are in the database, then we could use the max primary key, or filter out those records which don't have a publish date.
So, filtering out the test cases for Webcast itself, and the data access layer, then we'd need one - an interaction-based tests which verifies that GetLatestWebcast calls the appropriate DAL method.
It depends on what the GetLatest() method's dependencies are. You probably don't have to test the Webcast class unless there is actually code that you have written.. if it's just a bunch of properties, there is no need to test whether the .NET framework does its job.
42; always 42.
It depends on the purpose of the class this method comes from. Is it the ultimate source for information on Webcasts, or is it just your local access point for it.
In other word, does this class hold a handle to a database connection or a RSS feed; or is it the database?
If it is the ultimate source, then there are probably a lot that should be done, but say which would require more intimate details of the class.
If it's local the local access point, then you are pretty much limited to range/reasonableness checks on the properties of the returned object. Anything beyond that, you aren't testing the method, your're testing the mocks.
You must not forget the case where there are 0 webcasts or where the colection is null.
Why PublishDate is nullable?
Any attempts to answer this question that aren't phrased along the lines of "can you tell me more about the acceptance criteria" will be addressed by our human resources staff during your exit interview.
I agree David, always 42!! ;)
Because you may want to have a webcast that is not published.
1, if you accept whitebox tests.
More information is needed. What are the rules surrounding the publishing of web casts? Can more than one webcast be published on the same date? If so, do you rank them by their Id? How is a null PublishDate handled - is it in the future or in the past?
Another vote for more information:
Does it throw exceptions? If so, what ones, and why?
Does it GetLatest() modify the state of the instance of the type it's contained in. If so, under what conditions?
Is a null a valid return value. If so, under what conditions will this occur?
...plus the other questions about more information.
What is the current datetime ... because the "Latest" may well depend on that too....
Scott got it :)