Wednesday, May 12, 2004
Nant, nunit, and config files

I've been stabilizing our build process at work, and have found some oddities in using nant and nunit.  The issue's roots seem to come from handling of config files.

Here is what's happening.  We maintain a “program” solution, and a “test” solution.  The program solution has its own config file, and we needed a way to have the test solutions also carry a config file.  We tried a number of different ways, but ended up using a test.config, which the testfixtures copy to assemblyname.test.dll.config for automated testing.

The nunit2 task in nant supports providing a assembly, and a config file.  So I went from using a fileset including **.test.dll, to using a number of <test> tasks, each individually specifying the assembly and the config file.  This seemed to get close to working, but would still intermittently throw odd errors that I couldn't track down.  The part that gets me, is calling nunit-gui or nunit-console on the same assemblies would not throw an error.  Looking into the nant code, we saw that nant creates a new appdomain, and that’s why when using the nant task you must specify the config file, but it doesn’t seem to work, or at least not reliably.

After hours of mucking around with config files, and tasks in nant, I finally broke down and added an <exec> task calling nunit-console for each assembly we wanted to test.  It is not as dynamic as I was shooting for, but now it seems to work very reliably, so I am willing to sacrifice flexibility to reliability in this instance.

My question, though, is who else has seen behavior like this?  We have the nunit2 task working for assemblies without config files, but with them it just doesn’t seem to fly.  Anyone else notice this?

 



1/23/2005 3:53:35 PM (Eastern Standard Time, UTC-05:00)
1/23/2005 3:53:35 PM (Eastern Standard Time, UTC-05:00)
1/23/2005 3:53:35 PM (Eastern Standard Time, UTC-05:00)
Interesting. I haven't had any problems with the configuration not working. What version of the .NET Framework are you using? Do you have the latest NAnt (0.85 rocks, you need to get it!) and NUnit (2.1)?
<br>
<br>It's funny because I can only get NUnit to work reliably from NAnt. The nunit-gui and console confuse and frighten me and won't allow me to do fancy things with config files like I can from NAnt.
1/23/2005 3:53:35 PM (Eastern Standard Time, UTC-05:00)
That is funny. We were the exact opposite. We could get nunit gui and nunit console to test everything, but nant would throw an exception that I was able to trace back to config settings. It could be something funny we are doing auth wise (we use our own implementation of IIdentity/IPrincipal) and replace the thread context with our own, all before config settings are called.
<br>
<br>We use framework 1.1, nant 0.85 and nunit 2.1. All the latest as of 5/12 (the day I posted this was the last time I touched that part of the build).
<br>
<br>I tried just about everything, even using static .nunit files, and loading those through the nunit2 task. As soon as I went to &lt;exec it worked perfectly, and has for every build now.
<br>
<br>I do plan on trying to rmedy this one day though, if for nothing else to try to fix the test results being emailed by ccnet.
<br>
<br>
1/23/2005 3:53:35 PM (Eastern Standard Time, UTC-05:00)
We have the exact same experience, however also with the exec I still get the error that the fixture cannot be executed. The local config file is generated but remains empty.
1/23/2005 3:53:35 PM (Eastern Standard Time, UTC-05:00)
What is the exact error? We were not getting an error like that but rather an instance error where it was expecting something from config that wasn't there, so it was our app throwing the error not nant. This sounds more like nant or nunit throwing something. You are creating a config file in the TestFixtureSetup before anyone makes a call to config? Also, how are you naming your config file, and are you specifying a config file either through an nunit file or via a param?
1/23/2005 3:53:36 PM (Eastern Standard Time, UTC-05:00)
Yes,
<br>
<br>I had to resort to the same thing. If you are testing a multi thread application you may want to consider using the /thread option also when exec nunit-console.exe.
1/23/2005 3:53:36 PM (Eastern Standard Time, UTC-05:00)
I have been experiencing a very similar problem. We have modified CCNet (0.6.1) a bit, and we use CCNet to build our modified version. We're using the .build that ships with it, but noticed that it uses &lt;exec&gt; to run tests. We want to get the test result reporting so I tried switching to &lt;nunit2&gt; tasks so that the test results would get into the build log. For some reason, some tests were failing when run under the &lt;nunit2&gt; task. All of the tests pass using the nunit-gui, nunit-console and even the &lt;exec&gt; task.
<br>
<br>Anybody have thoughts on that?
3/21/2005 1:33:03 PM (Eastern Daylight Time, UTC-04:00)
I have a similar problem. All of my test are passing when ran from the GUI and the console. However, using the nunit2 task from nant keeps failing. My test assembly are accessing a remoting component that takes care of the login information using the principal and the network login. Dont know what the cause is, but I just switched to the exec task and it is running. oh well.
3/21/2005 2:11:46 PM (Eastern Daylight Time, UTC-04:00)
That was pretty much where we were. It is still working with the exec task, so I never even went back to look at it again. Which version of nunit and nant are you using?


Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):