[Mono-list] Unit tests load a different configuration file under mono

Charlie Poole charlie at nunit.com
Fri Aug 9 23:14:07 UTC 2013


Each test framework has it's own requirements for where a config file must
be located and how it should be named in order to be loaded and used. Those
requirements are necessarily different from how .NET normally locates
config files because following the .NET rules would load the config for the
test runner itself rather than for your tests.

In the case of NUnit, you can find the required info at
http://www.nunit.org/index.php?p=configFiles&r=2.6.2

Charlie


On Fri, Aug 9, 2013 at 3:24 PM, David Curylo <curylod at asme.org> wrote:

> I ran into an issue several months back where my code could not find
> ConnectionStrings while running my code in NUnit under mono, however, I was
> having trouble making a simple reproducible test case.  Now I have one, and
> I suspect that it is not an NUnit issue, as the same thing happens under
> xUnit.  Rather, I'm guessing that this has to do with how the AppDomain in
> mono resolves configuration file locations in shadow copied assemblies like
> those used by unit testing frameworks.
>
> My simple test is below.  The first test will succeed, but the second one
> will fail only under mono (tried versions 2.10.8.1, 3.0.2, 3.1.2, and
> 3.2.0). Under MS.NET <http://ms.net/>, both will succeed.  The only
> difference in the first and the second test is that the second test uses
> HttpUtility from System.Web, and when this happens, the
> ConfigurationManager.ConnectionStrings changes to the default one from
> ASP.NET <http://asp.net/>, containing a LocalSqlServer (SQLEXPRESS) and
> LocalSqliteServer.
>
> Is anyone able to explain why this would happen only in the AppDomains as
> created by unit testing frameworks?  Any known workarounds for this to keep
> it from loading a different config?
>
> ### TestCode.cs ###
>
> using System;
> using System.Configuration;
> using NUnit.Framework;
>
> namespace TestHarness
> {
> [TestFixture]
> public class MyClass
> {
>  [Test]
>  public void TestSomeCode1() {
>  var connStr = ConfigurationManager.ConnectionStrings["mystr"];
>  Assert.IsNotNull (connStr);
>  }
>  [Test]
>  public void TestSomeCode2() {
>  System.Web.HttpUtility.ParseQueryString ("http://foo.bz?bar=fu<http://foo.bz/?bar=fu>
> ");
>  var connStr = ConfigurationManager.ConnectionStrings["mystr"];
>  Assert.IsNotNull (connStr);
>  }
> }
> }
>
> ### App.config ###
>
> <configuration>
> <connectionStrings>
>  <add name="mystr" connectionString="test at whatever.net" />
> </connectionStrings>
> </configuration>
>
>
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-list/attachments/20130809/fe6557a1/attachment.html>


More information about the Mono-list mailing list