Running WatiN tests with ReSharper testrunner - nunit

I'm getting started with WatiN to test my web interface. The problem I'm having is the following:
When I start the tests from within TestDriven.net, I have no problem. If I use the ReSharper test runner, I get this predictable AppartmentState exception.
I tried using the different options described here: http://watin.sourceforge.net/apartmentstateinfo.html#testdriven. Nothing helps.
Any suggestions?

I've use Resharper test runner in most of my watin test projects. To get it to work use the same method as for nunit:
http://watin.sourceforge.net/apartmentstateinfo.html#nunit
App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<!-- Valid values are STA,MTA. Others ignored. -->
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>

With NUnit 2.5, RequiresSTA attribute should be the tool of choice.

Using Resharper 5.1 with VisualStudio 2010 Ultimate I found that I needed to change my Resharper options to disable "Shadow-copy assemblies being tested" (found in Resharper --> Options --> Tools --> Unit Testing).
Additionally, I also found that the correct naming for the config file is the one which includes the dll extension (so: assemblyname.dll.config).

Related

CruiseControl.Net plugin for nunit3

It seems that the syntax for running nunit has changed between nunit 2 and 3. I would like to move my existing CruiseControl.Net configuration to use NUnit 3, but I cannot work out how to modify my existing target (see below) to use nunit3. Is there documentation anywhere? Thanks for any help.
<nunit>
<environment>
<variable name="TEST_FILES_DIRECTORY" value="C:\TestPlans\TestFiles" />
</environment>
<path>C:\nunit3\Compiled\nunit3-console.exe</path>
<assemblies>
<assembly>C:\source\TestRunner\bin\Debug\Tests.dll</assembly>
</assemblies>
<includedCategories>
<includedCategory>Data</includedCategory>
</includedCategories>
<timeout>72000</timeout>
</nunit>

NUnit - "Test load failed System.ApplicationException: Unable to find test in assembly"

I am using NUnit 2.6.3 and .NET framework 4.5.
I have a file, Test.NUnit, in my test project which contains:
<NUnitProject>
<Settings activeconfig="Debug"
appbase="E:\Test" />
<Config name="Debug" binpathtype="Auto">
<assembly path="bin\Debug\Test.dll" />
</Config>
<Config name="Release" binpathtype="Auto" />
</NUnitProject>
When I try to run this file I get an error message
Test load failed System.ApplicationException: Unable to find test in assembly
The problem is similar to this question. However, I can't get the answer to work.
I have a Test.dll.config file in my project which is located in E:\Test.
It contains:
<startup useLegacyV2RuntimeActivationPolicy="true">
<!--<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />>-->
<supportedRuntime version="v4.0.30319" />
</startup>
I have tried both versions of the supportedRuntime to show that I am using .NET framework 4.5.
I had a similar issue. Check your firewall blocking nunit-agent.exe trying to connect 127.0.0.1.
NUnit uses it for running tests and doesn't show the correct error if it can't connect to 127.0.0.1.

Do the SetUp and TearDown methods need [RequiresSTA] if tests have it?

I can run my WatiN tests with ReSharper without issues. Each test has the RequiresSTA attribute and runs fine.
When I try run all the tests in the class (TestFixture) I get the following error:
One or more child tests had errors
Exception doesn't have a stacktrace
<testname> ignored: Invalid signature for SetUp or TearDown method: TestSetup
<testname> ignored: Invalid signature for SetUp or TearDown method: TestSetup
<testname> ignored: Invalid signature for SetUp or TearDown method: TestSetup
The error doesn't indicate what I need to change to make it work.
If I then select all the tests that have been ignored in the Unit Test Sessions window, I can run them without problems.
What must I change to allow me to run all the tests in the TestFixture?
I have met the same problem. I changed SetUp() and TearDown() methods to be public, then it worked.
I've always set the apartment state in the App.config file of my solution and the NUnit GUI runner runs entire fixtures as expected.
App.config starts off like this.
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<!-- Valid values are STA,MTA. Others ignored. -->
<add key="ApartmentState" value="STA"/>
</TestRunner>
</NUnit>
<appSettings>
........
Edit: I'm using Watin2.1 and NUnit 2.5.

Running WatiN tests with Nunit error?

When I try to run a WatIn test trough the NUnit ide, I get the error message:
ConsoleApplication1.Tests.CanBrowseToMicrosoft:
System.Threading.ThreadStateException : The CurrentThread needs to have it's ApartmentState set to ApartmentState.STA to be able to automate Internet Explorer.
I created an application configuration file called ConsoleApplication1.exe.config which is below:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="ApartmentState" value="STA" />
</TestRunner>
</NUnit>
</configuration>
My class Tests.cs is below:
[TestFixture]
public class Tests
{
[Test]
public void CanBrowseToMicrosoft()
{
using (var browser = new IE())
{
browser.GoTo("http://www.microsoft.com/");
Assert.That("Microsoft Corporation", Is.EqualTo(browser.Title));
}
}
}
Am I doing something wrong?
The other question I had was how do I get the NUnit test results to show up in vs2008 ide instead of having to run the NUnit Gui?
I figured it out, because I was loading an NUnit project called Tests.nunit, I need to call the application configuration file Tests.config. After this change, it worked fine.
There is a cleaner way to resolve your issue with STAThread requirement, but it requires NUnit 2.5.
Also, have you tried TestDriven.Net to run unit tests from Visual Studio?

Getting a version 2.0 is not a compatible version when running NUnit

I am trying to run the sample tests for NUnit, and I am getting an error. I have the supportedRuntime versions set to v1.0.3705 up to v2.0.50727. I have the requiredRuntime version set to v2.0.50727. Is this the wrong setting?
The following is the error that shows:
Metadata file 'c:\Program Files\NUnit 2.4.8\bin\nunit.framework.dll' could not be opened -- 'Version 2.0 is not a compatible version.'
I got the same problem with the CSharp examples in 2.4.8 "right out of the box" with VS2005. Here's my solution.
In nunit.exe.config, the following block is commented-out by default. Put it back in.
<startup>
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v2.0.50215" />
<supportedRuntime version="v2.0.40607" />
<supportedRuntime version="v1.1.4322" />
<supportedRuntime version="v1.0.3705" />
<requiredRuntime version="v1.0.3705" />
</startup>
It sounds like you did that but changed the requiredRuntime from the default of v1.0.3705 to v2.0.50727
After that, I opened the CSharp project in VS2005 and converted it. The nunit.framework references all had the icon that shows they are wrong. So I deleted the nunit.framework reference from all 4 projects:
cs-failures
cs-money
cs-money-port
cs-syntax
Then I added new references to C:\Program Files\NUnit 2.4.8\bin\nunit.framework.dll to replace them.
After that the project builds fine.