Domanda

I'm having problems with my unit tests. The problem is: I'm using Sitecore. Another question I asked about this is: Unit Testing Sitecore LicenseManager

My problem is that I get the exception:

Test method foo.Bar.Framework.Tests.Core.UnitTest1.TestMethod1 threw exception: 
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Sitecore.Services.Heartbeat' threw an exception. ---> System.InvalidOperationException: Could not read Sitecore configuration.

I looked into the code with dotPeek and the function Sitecorre.Configuration.Settings.GetSetting("HeartbeatInterval") throws an exception. Because it can not read the configuration. When I add the same code to my unit test .cs file and debug the test it can read the configuration. The setting is also available in the app.config

It looks like the referenced assembly cannot read the config and the test itself can. How can I fix this?

EDIT

The Settings.GetSetting() function eventually uses Sitecore.Configuration.ConfigReader.GetConfigNode(). This Function eventually uses this function:

private static ConfigReader GetReader()
{
    return ConfigurationManager.GetSection("sitecore") as ConfigReader;
}

So... Why can't the referenced dll read the app.config through the ConfigurationManager?

È stato utile?

Soluzione

It turned out to be the *.testsettings. When I ran it on my pc it worked but on the build server it did not. Turned out I just had to commit the *.testsettings and include the /testsettings parameter

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top