NUnitAsp
ASP.NET unit testing

Frequently Asked Questions

The NUnitAsp team sees frequently asked questions as indicators of problems with NUnitAsp. We strive to eliminate FAQs by improving NUnitAsp itself, so this isn't the best place to start for general information about NUnitAsp. For an overview, see the NUnitAsp QuickStart Guide. For a detailed tutorial, see the NUnitAsp Tutorial. For installation issues, see the Installation Guide. NUnitAsp is available for download at the NUnitAsp web site.

Q: How do I test if a page has redirected properly?

A: Use the Browser.CurrentUrl property to look at the current URL or the CurrentWebForm.AspId property to look at the ASP.NET ID of the current web form.

Q: How do I test user controls and stuff in data grids?

A: See the section titled "User Controls, Data Grids, and Other Control Nesting" in the Quick-Start Guide.

Q: How do I test a site that requires authentication?

A: Use the Credentials property on HttpClient to set your login credentials. For example, to use your current login, you would use this code:

Browser.Credentials = CredentialCache.DefaultCredentials;

You may also include a username and password when you retrieve a URL:

Browser.GetPage("http://username:password@example.com/myPage.aspx");

Q: Why doesn't NUnitAsp support frames / Javascript / pop-up windows / more HTML controls?

A: NUnitAsp's purpose is to enable test-driven development of ASP.NET code-behind methods. If you use NUnitAsp to do so, you'll find that the lack of Javascript, etc. is much less of an issue. When you write an NUnitAsp test, focus on testing the behavior of a specific page or even a specific user control. We expect you to ignore frames, Javascript, and other client-side issues and focus on testing code-behind logic.

We would like to provide more robust client-side support, but given our limited manpower, we have decided to focus on the code-behind unit-testing aspect of NUnitAsp instead.

Q: But what about AJAX?

If you have server controls that generate client-side AJAX, you can test the server-side component with a custom tester that imitates the client-side behavior. You can't test the client-side behavior with NUnitAsp; NUnitAsp is meant for testing server-side ASPX code-behind.

Q: When I try to compile NUnitAsp in VS.NET, I get a "cryptographic failure" error. What's wrong?

A: The NUnitAsp DLL is strong-named, which means it must be signed by a cryptographic key. If you try to compile without a key, you'll get this error message:

Cryptographic failure while signing assembly 'C:\projects\NUnitAsp\source\NUnitAsp\obj\Debug\NUnitAsp.dll' -- 'The key container name 'NUnitAsp' does not exist'

We don't include a key in the distribution, but the NUnitAsp build script automatically generates the correct kind of key for you. Open a Visual Studio .NET command prompt and type 'nant' in the root NUnitAsp directory to run it. You only need to do this the first time you compile.

Q: When I try to compile NUnitAsp with NAnt, the build says "External program returned errors". What's wrong?

A: The build script is set up to work with .NET 1.0 by default. It sets an environment variable called DotNetToolDir to point to your .NET 1.0 directory. If that directory doesn't exist, the build won't be able to find "sn.exe" and will fail with this error:

keypair:
[exec] sn -k NUnitAsp.snk

BUILD FAILED
C:\projects\nunitasp\NUnitAsp.build(50,4): External program returned errors, see build log for details.
Try 'nant -help' for more information

To correct this, make sure you've set DotNetToolDir correctly and that sn.exe is in that path.

Once you have that working, NAnt will give you a different error:

BUILD FAILED
C:\projects\nunitasp\NUnitAsp.build(90,6):
[csc] C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705\csc.exe failed to start.
The system cannot find the file specified

This error occurs because NAnt uses .NET 1.0 by default. At this point, you can use Visual Studio to build or you can edit NAnt.exe.config in the lib\NAnt directory. If you edit the config file, set the default framework to 1.1:

<frameworks>
  <platform name="win32" default="net-1.1">
    ...
  </platform>
</frameworks>

Many thanks to Ted Husted for pointing this out and to Cory Foy for blogging the solution.

Q: How do you spell "NUnitAsp?"

A: "NUnitAsp" is spelled in accordance with .NET framework naming standards. Like .NET's "HttpWebRequest" and "SqlConnection" classes, the first letter of each word is capitalized and acronyms are treated as a single word: N Unit Asp. It's pronounced "en unit a ess pee." It is not spelled "NunitAsp," "NUnitASP," or (heaven forbid) "nUnit.ASP."

Last updated for v2.0.