views:

216

answers:

3

I'm using Cruise Control.NET and NAnt to automatically run NUnit tests on our code base. Some tests cause Windows forms to be shown. When these tests are run manually from VS or NUnit GUI, they work fine. When run via the Cruise Control service, I get the following exception:

System.InvalidOperationException : Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.

Short of excluding the test altogether or rewriting the test so the form is not shown, is there any other way I can modify the test or get NUnit to run these tests when called from a service?

+1  A: 

You can have always logged-in user, and attach the service to the user session(how to create interactive services). But, it's better if you modify your code and tests, so the winform stuff is abstracted.

Sunny
+1  A: 

I usually mark such tests with attribute [Explicit] so they will only be run when I run them explicitly and not on the CCNET server. Other approach could be to mock up the behavior of the screen so there is no need to show it.

dh
this attribute can be added to a single test method or the complete test fixture
dh
+1  A: 

You might run those tests by executing CCNET from command line instead of executing CCNET as a service.

However I would recommend to keep different levels of testing apart from each other. If a test gets complicated i.e., it needs a more complex setting in order to run (e.g. special user interaction), this test is more an integration or acceptance test than a unit test (even if it uses NUnit).

The Chairman