Unit Testing scalability and performance - ISerializable - Roy Osherove's Blog

Unit Testing scalability and performance

I had an interesting chat with Clemens today. I told him about the Rollback ability using ES and he totally disagreed with me that its a viable option for testing database usage for several reasons:
  • If you run tests with LOTS of data - rollback will take a loooong time
  • You're introducing "context" into your running code - thus changing is runtime behavior, even if ever so slightly
  • If you have components that require new transactions or do not support transactions you can't use this technology
So how does he do it? he restores the database every time. Costly? yes - but less expensive than the other way and the weaknesses just listed won't happen. But more importantly - why is this big difference in opinion happening? why do these rollbacks seem perfectly natural to me and so unnatural and irrelevant to him? Its because we're doing the testing in different ways of thinking. Clemens is testing scalability issues and integration issues in a much more fierce manner than I have ever though about doing. I guess it comes with the territory. Personally - I never needed such tests. What would be required to test load balancing, scalability and perf issues?
  • Multi threaded testing
  • Repeated - long running, large data volume tests
  • lots of interaction in the DB for DALs
My tests look nothing like this. I support the approach that when you test something you test it solely for its own functionality and nothing else. for example - an object that is supposed to behave in a specific way with other objects might be tested using mock objects to verify that it works fine. A DAL will be tested for the simple functionality it has, without multiple threads testing it. I know that it works. If I get a scenario that fails it - *then* I'd test the harder stuff. here are pointers from my testing needs:
  • they should run as fast as possible so that you can run them all the time. all of them.
  • they should test individual object functionality - often using mock objects and interfaces
  • Against the database I will test the simplest functionality until I need something bigger. Scalability testing does enter this field until I *need* scalability. KISS principle.
So - what's the big deal? we're  both working on the same direction - on different paths. I do suspect a time will come when I will need to get into hardcore perf and scalability testing. I know Rollback won't help me then. But being able to restore a database easily will.
Hopefully - both of these will be available via attributes in my unit tests. It's possible even today - with a little effort.
Published Tuesday, July 20, 2004 1:34 AM by RoyOsherove

Comments

Monday, July 19, 2004 6:47 PM by Me

# re: Unit Testing scalability and performance

Rory - Unit testing and performance testing are two different things. For perf testing, yes you should restore the database but NUnit or any other unit testing tool is not the right tool for it. I think you are in the right track with your method of rolling back. Unit tests and scalability test/performance tests are two different things.
Monday, July 19, 2004 8:58 PM by Anatoly Lubarsky

# re: Unit Testing scalability and performance

When you talk about database testing performance and scalability issues you have to deal with blowing up database and running (some staff you can test only on the production environment though). You have to deal with index tuning, transaction log handling, etc. BTW, there is no need to restore the database just attach/detach (take offline/bring online). IMHO rollbacks are not suitable here, they do change runtime behaviour. Besides, you measure performance mostly on selects and not DML when you deal with databases.
Tuesday, July 20, 2004 9:38 AM by Philip Nelson

# re: Unit Testing scalability and performance

Yup, I commented on this in your original blog about this. As our number of tests went up, the time it takes to run the tests got to the point where developers were no longer running all the tests. Using transactions to rollback as a techniques was the first thing to go as it added enomous amounts of time to the run.

Currently, I am working on having my dal support mock objects directly, so support the idea that the details of how a class accesses data shouldn't be exposed on thier interfaces, but instead the dal can be manipulated by the test code to use mocks while in the test environment. In that way, I can support test data in files, mock data written in code, very small test databases that can be restored quickly, and substituting faster test optimized queries to get expected results.
Wednesday, July 21, 2004 3:52 AM by TrackBack

# TDD with a database - one good solution

TDD with a database - one good solution