views:

129

answers:

4

Has anyone worked at a large company, or on a very large project, that successfully used unit testing?

Our current database has ~300 tables, with ~100 aggregate roots. Overall there are ~4000 columns, and we'll have ~2 Million lines of code when complete. I was wondering - do companies with databases of this size (or much larger) actually go through the effort to Mock/Stub their domain objects for testing? It's been two years since I worked in a large company, but at the time all large applications were tested via integration tests. Unit testing was generally frowned upon if it required much set up.

I'm beginning to feel like Unit testing is a waste of time for anything but static methods, as many our test methods take just as long or longer to write than the actual code ... in particular, the setup/arrange steps. To make things worse, one of our developers keeps quoting how Unit Testing and Agile methods was such an abject failure on Kent Beck's Chrysler project ... and that it's just not a methodology that scales well.

Any references or experiences would be great. Management likes the idea of Unit Testing, but if they see the amount of extra code we're writing (and our frustration) they'd be happy to back down.

+1  A: 

I've had some good experiences with mock objects and unit testing in projects where there was a lot of upfront design and a comfortable timeline to work with -- unfortunately that is often a luxury that most companies won't afford to take a risk on. GTD and GTDF methodologies really don't help the problem either, as they put developers on a release treadmill.

The big problem with unit tests are that if you don't buy-in from a whole team what happens is one developer looks at the code with rose colored glasses (and through no fault of their own) implements only the happy path tests which are what they can think of. Unit tests don't always get kept up as well as they should because corner cases slip by, and not everyone drinks the Kool-Aid. Testing is a very different mindset than coming up with the algorithms, and many developers really just don't know how think that way.

When iterations and development cycles are tight, I find myself gaining more confidence in the code quality by relying on static analysis tools and complexity tools. (FindBugs, PMD,Clang llvm etc) Even if they are in areas that you can't directly address, you can flag them as landmines and help better determine risk in implementing new features in that area.

David Sowsy
+1  A: 

If you find that mocking/stubbing is painfull and takes a long time then you probably have a design that is not made for unit-testing. And then you either refactor or live with it.

I would refactor.

I have a large application and see no trouble in writting unit-tests and when I do I know it's time to refactor.

Of course ther is nothing wrong with integration test. I actualy have those too to test the DAL or other parts of the application.

All the automated test should form a whole, unittest are just a part of those.

chrissie1
Hi Chrissie. Here's a super simple example. Let's say I have a single line of code to get an order type based on a passed in code. The simplified call using Linq is: OrderTypeObject orderType == FetchOrderTypes().Where(x => x.IsSaleable . I can test this against the database with 3 LOC (1 for each assert), but testing against mocked data requires 8-10 extra LOC. 11 LOC to test 1 hardly seems efficient ... and it's hard to argue that the single line presented needs refactoring.
Jess
I just see that you need an ordertype object which would be easily got in one line of code if FetchOrderTypes is Mockable (Interface/Baseclass) But I guess it isn't. And perhaps you only need 3 LOC but you also need to setup the database with the correct data which you don't seem to acount for, or do they magically appear?
chrissie1
A: 

Yes they do. Quite extensively.

The hard part is getting the discipline in place to write clean code - and (the even harder part) the discipline to chip away at bad code by refactoring as you go.

I've worked in one of the world's biggest banks on a project that has been used from New York, London, Paris and Tokyo. It used mocks very well and through a lot of discipline we had pretty clean code.

I doubt that mocks are the problem - they're just a fairly simple tool. If you've got to rely on them super-heavily, say it looks like you need mocks of mocks returning mocks - then something has gone wrong with the test or the code...

cartoonfox