Testdriven.net ad hoc tests and XNA
By Henning Degn (mail me)
Updated 2007-05-17 21:51
This article is about issues with Testdriven.net and XNA. As such, it assumes you already have both Testdriven.net and the XNA Framework installed.
Update: A previous solution posted here has been removed, as a newer and a lot easier method has come forth. I’m not even going to let you know the previous solution! It was that bad! :)
Credits for this workaround should go to Jamie Cansdale at Testdriven.NET (WOW great support!) for troubleshooting this issue and designing a helper class.
Note: Testdriven.net 2.0 RTM didn't include support for Visual Studio Express editions. However, all betas of Testdriven.net since 2.5 works fine in XNA game studio express
Some tests in XNA cannot be done dynamically. These tests usually require visual inspection and therefore need to be run manually. Using Testdriven.net you can run test scenarios, simply using an ad hoc test of a function containing the test. Simple. Effective. No need to modify the main method to run these functions.
However, when using any XNA content I have stumbled on the following error:
Microsoft.Xna.Framework.Content.ContentLoadException: Error loading "Content\myTexture". File not found. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\WINDOWS\assembly\GAC_32\Microsoft.Xna.Framework\184.108.40.206__6d5c3888ef60e27d\Content\myTexture.xnb'
The reason being that (naturally) I didn’t put my content inside the GAC (Global Assembly Cache)! The ContentManager is using the codebase of the assembly who’s main method called it as its root. Since Testdriven.net ad hoc tests can’t supply this to the content loader, it default to is own location… inside the GAC (a pretty poor design decision, content will NEVER be located here).
Nothing can be done about this, unless someone convinces the XNA team to use ‘AppDomain.CurrentDomain.BaseDirectory’ instead. :-)
A Workaround do exist however!
A simple utility class can be used to manually set the Entry Assembly, allowing XNA content loading to continue correctly.
Download AssemblyUtilities.zip and unpack into your project and add it to your solution.
For every ad hoc test you wish to run, use the command:
This needs to be called before content loading, such as in the first line.
An example of an ad hoc test can be seen here:
public static void myAdHocTest()
//Do your testing here
Run the ad hoc tests like normal, by putting the caret in the test, right-click and choose “run test(s)”.
Comments? Send me a mail!