Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

I have been working on a CSLA project for the last few months. We are working on refining our unit testing now that we have implemented our authorization rules. All good. We are working VS2005. Honestly, I like CSLA in many ways, but there are few gotchas we've seen along the way. This post outlines one of them.

However, we noticed something today. We establish our starting conditions in our ClassIinitalize in the TestClass. When we have only one TestMethod in the class, this works fine. We recently included several CRUD tests in one TestClass for a particular class. We established our CSLAPrincipal in the ClassInitalize as we have done in all our others. Suddenly, several of our tests started failing, where before they worked. The failures were all related to an error message indicating that our authorization rules were doing their job; somehow our authorization was going awry.

I checked the CSLAPrincipal on the start of the first test, and it was fine; we were in role. However, each subsequent test, we were NOT in role! The CSLAPrincipal role had been changed to a generic CSLAPrincal, not the one we set. This seemed odd, so I changed the test to place the CSLAPrincipal initialization in the TestInitialize. This works fine.

We realized that the test thread must end once the first test is set, and the CSLAPrincipal is cleared out. Since we set this only once previously, we never set it again. We also realized that the VSTS unit tests run the ClassInitialize for all the TestClasses in a run before the first test is initialized, or that it seems so anyway.

So, after much cussing and debugging of our tests, we figured it out: be sure to set your CSLAPrincipal in your TestInitialize instead of ClassInitialize.

Posted on Tuesday, May 22, 2007 11:30 PM | Back to top


Comments on this post: CSLA: an interesting behaviour with Unit testing

Comments are closed.
Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: GeeksWithBlogs.net