views:

272

answers:

1

Dear ladies and sirs.

I have recently encountered some inconsistencies in running unit tests inside VS2008 vs running the same unit tests with mstest on the command line.

My scenario is a bit advanced, so I have probably hit some corners. I have many data driven unit tests running against the same DataSource. I also like experimenting with PostSharp. So, I have written a PostSharp aspect - TestDataSource - which I apply to a unit test type, not the unit test methods. When the type is built, this aspect instructs PostSharp to attach the DataSource attribute to each and every unit test method in the type.

Examining the built assembly in Reflector shows that each test method is indeed attributed with the correct DataSource attribute. Running the tests with mstest on the command line behaves as expected - each test is run against the specified data source.

However, running exactly the same unit tests in VS2008 fails to find the data source. It is as though VS2008 ignores the built assembly and looks at the source code, which, of course, does not appear to be a data driven test, because the DataSource attribute is injected during the build.

There is no problem with deployed items. Attaching the DataSource manually to the tests makes VS2008 run them happily.

Any ideas?

Thanks.

A: 

If you put a breakpoint in your test and inspect the list of loaded modules, you should see which is the exact path of the assembly you are debugging. Is it the expected one (in bin\Debug)? If you open this file using Reflector when the debugger is running, do you see PostSharp stuff inside?

What's strange is that a part of PostSharp unit tests are written for MSTest and they run from Visual Studio without problem...

-gael

Gael Fraiteur
The loaded assembly is not from bin\Debug, since it is an mstest unit test. It is copied to the dedicated deployment directory. But it is the correct assembly. When I inspect it with reflector while the debugger is running I do see the DataSource attribute injected by PostSharp on the respective unit test method.I do not know if it matters, but our products are not built into bin\Debug, rather all the projects are built into a single consolidated bin directory outside the solution folder.DataSource is a special attribute. Have you tried PostSharping it?
mark
BTW, do you prefer me to open a thread on PostSharp forums for this?
mark
It's easier for me indeed to monitor the PostSharp forum.If you are sure that MSTest loads the proper, enhanced, assembly, then I don't know what can be wrong.
Gael Fraiteur
Would you like me to isolate the case and post on PostSharp forums the relevant projects?
mark
Yes, if you can. Thank you.
Gael Fraiteur
I have migrated from mstest to MbUnit, so it is not worth the effort now. Thanks anyway.
mark