I am currently writing some unit tests for a library which I've written. As an example, say I'm testing a particular a method called doSomething() then my test structure would be something like as follows:
Perhaps the second approach is better as the assert is more granular and so it will be easier to tell exactly where the error occurred? Any thoughts much appreciated.
Find the happy medium that gets you to where the error is found.
One way to do it: if you are testing a function, and it gives the wrong answer, if its calls other functions, you unit test those next. If those call more functions, you unit test those ... and so on down the chain until you hit the end of the tree where the functions do something and return. Each function should have a test. If none of the functions fail their tests, the top level one should be the problem or your unit tests are no good.
You can do this with some smarts, though. You can filter the above using your source control to only test what changed since the last time everything worked.