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

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.

Related

Could not load file or assembly 'ClearScriptV8.win-x64.dll' or one of its dependencies. The module was expected to contain an assembly manifest

I have .NET MVC app (.NET Framework 4.6.1) and I want to add ClearScript to my app.
I've added package Microsoft.ClearScript via NuGet and after launch app I have error:
Could not load file or assembly 'file:///D:\PathToProject\bin\ClearScriptV8.win-x64.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
This file is in bin folder
What am I doing wrong? And how can I resolve this issue?
UPDATE
The next step I did removing assemblies into web.config files as #BitCortex advised:
<system.web>
<compilation>
<assemblies>
<remove assembly="ClearScriptV8.win-x64" />
<remove assembly="ClearScriptV8.win-x86" />
</assemblies>
</compilation>
</system.web>
but it didn't help.
In the result I've comment out these strings into .csproj file:
<Import Project="..\packages\Microsoft.ClearScript.V8.Native.win-x86.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x86.props" Condition="Exists('..\packages\Microsoft.ClearScript.V8.Native.win-x86.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x86.props')" />
<Import Project="..\packages\Microsoft.ClearScript.V8.Native.win-x64.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x64.props" Condition="Exists('..\packages\Microsoft.ClearScript.V8.Native.win-x64.7.2.5\build\Microsoft.ClearScript.V8.Native.win-x64.props')" />
<Import Project="..\packages\Microsoft.ClearScript.V8.ICUData.7.2.5\build\Microsoft.ClearScript.V8.ICUData.props" Condition="Exists('..\packages\Microsoft.ClearScript.V8.ICUData.7.2.5\build\Microsoft.ClearScript.V8.ICUData.props')" />
Now the initial issue was fixed but during executing script I see the following error:
Cannot load ClearScript V8 library. Load failure information for ClearScriptV8.win-x64.dll:
C:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\vs\...\runtimes\win-x64\native\ClearScriptV8.win-x64.dll: The specified module could not be found
C:\Users\User\AppData\Local\Temp\Temporary ASP.NET Files\vs\...\ClearScriptV8.win-x64.dll: The specified module could not be found
D:\pathtoproject\ClearScriptV8.win-x64.dll: The specified module could not be found
D:\pathtoproject\bin\ClearScriptV8.win-x64.dll: The specified module could not be found
C:\WINDOWS\system32\ClearScriptV8.win-x64.dll: The specified module could not be found'
What am I doing wrong? And how can I resolve this issue?
What's assembly manifest from initial issue? Maybe some .xml file was missed into package folder or something else? (because I see in bin folder for example ClearScript.V8.dll and ClearScript.V8.xml files)
Try excluding ClearScript's native assemblies from compilation by merging the following into all of your Web.config files:
<system.web>
<compilation>
<assemblies>
<remove assembly="ClearScriptV8.win-x64" />
<remove assembly="ClearScriptV8.win-x86" />
</assemblies>
</compilation>
</system.web>

Cannot run nunit tests with Nant

I'm trying to launch nunit ui tests with nant and get the error:
Buildfile: file:///c:/UItests/nant.build Target framework:
Microsoft .NET Framework 4.0 Target(s) specified: build
build:
[nunit2] 2012/06/20/13:29:52: Exception in set up method: The
CurrentThread needs to have it's ApartmentState set to Apar
tmentState.STA to be able to automate Internet Explorer. [nunit2]
2012/06/20/13:29:52: Exception in set up method: The CurrentThread
needs to have it's ApartmentState set to Apar tmentState.STA to be
able to automate Internet Explorer. [nunit2] 2012/06/20/13:29:52:
Exception in set up method: The CurrentThread needs to have it's
ApartmentState set to Apar tmentState.STA to be able to automate
Internet Explorer. [nunit2] 2012/06/20/13:29:52: Exception in set
up method: The CurrentThread needs to have it's ApartmentState set to
Apar tmentState.STA to be able to automate Internet Explorer.
[nunit2] 2012/06/20/13:29:52: Exception in set up method: The
CurrentThread needs to have it's ApartmentState set to Apar
tmentState.STA to be able to automate Internet Explorer.
I tried with App.config that comes with my project, like this:
<test assemblyname="UITests.dll" appconfig="UITests.dll.config" />
And also I created config file manually and put it to folder with test and nunit assemblies. But nothing helped. In config file I have:
<add key="ApartmentState" value="STA" />
Here is nant.build file:
<?xml version="1.0"?>
<project name="UITests" default="build">
<property name="build.dir" value="" />
<target name="build">
<nunit2>
<formatter type="Plain" />
<test assemblyname="${build.dir}UITests.dll" appconfig="UITests.dll.config" />
</nunit2>
</target>
</project>
What I missed?
One possible and simple solution:
set this:
[assembly: RequiresSTA]
in AssemblyInfo.cs file.
Nant is able to run the tests but the TestSetup is doing something which is not configured properly. Probably try writing and running a simpler test like Assert.That( 10+1, Is.Equals(11)); and running that.
If it works then i think the question should be posted with more details on what and how you are testing

Moles creation does not create all objects

While trying to create a mole for some unit tests I noticed that some functions were not being 'moled'. Some functions were appearing in the xxx.moles.xml file while others were not.
To resolve this issue, I've tried reinstalling 'Pex and Moles', deleted files in the MolesAssembly folder, restarted the computer, etc.
Finally, I simply opened a console window and ran the moles.exe command from the command prompt.
"c:\program files\microsoft moles\bin\moles.exe" assembly.dll /op:"MolesAssemblies" /msbuild:"c:\windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe"
The first time I ran this, I received a message:
Moles : info : compilation : assembly metadata hash unchanged,
skipping code generation.
After deleting the moles in the MolesAssemblies folder, I ran the moles.exe command again and all my functions are now appearing in the xxx.moles.dll and xxx.moles.xml files.
Does anyone know why the mole generation does not work when building inside Visual Studio 2010, but it works perfectly from the command prompt?
I found the issue...I modified the .moles file before and only certain classes were added. I simply had to add more 'TypeName' and the classes/functions were included.
The reason that it 'worked' by using the moles.exe command was because I did not use the .moles file (I simply referenced the assembly). I changed the parameters for moles.exe to include the .moles file and the assembly and the results were identical to the output generated by Visual Studio. Once I notice that other parts of the code was breaking, I realized that the .moles file was incorrect.
I had something like this...
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
<Assembly Name="Assembly.name" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Fullname_1_0" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName ="Fullname_1_0" />
</Types>
</MoleGeneration>
</Moles>
I needed a second 'Add'
<Moles xmlns="http://schemas.microsoft.com/moles/2010/" >
<Assembly Name="Assembly.name" />
<StubGeneration>
<Types>
<Clear />
<Add FullName="Fullname_1_0" />
</Types>
</StubGeneration>
<MoleGeneration>
<Types>
<Clear />
<Add FullName ="Fullname_1_0" />
<Add TypeName="AdditionalClass"/>
</Types>
</MoleGeneration>
</Moles>
Be sure to REBUILD the test project, after modifying an assembly that is moled. Using the "clean" action on the test project will also fix this issue.

Running WatiN tests with ReSharper testrunner

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).

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.