XUnit in Visual Studio 2015 RC1 Update 1 doesn't find tests - unit-testing

I created an ASP.NET 5 project in Visual Studio 2015, using the Preview Templates. I installed XUnit via NuGet, and I added an "xUnit Test Project (DNX)" to my solution.
But my Test Explorer shows nothing, even though I have a public "Fact" test method in Class1.cs. When I "Run All Tests", the "Tests" output window is blank. My "Build" output window shows that 2 project build succeeds. (My ASP.NET 5 project, and my xUnit project.)
When I either build or clean my solution, however, I get the following message in the "Tests" output window:
------ Discover test started ------
------ Test started: Project: MyProjectTest ------
Starting Microsoft.Dnx.TestHost [C:\Users\xxxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnx.exe --appbase "C:\Users\xxxxxx\Documents\GitForWindows\Repositories\MySolution\MyProjectTest" Microsoft.Dnx.ApplicationHost --port 8424 Microsoft.Dnx.TestHost --port 8458 --parentProcessId 17312]
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Dnx.TestHost.Program.<>c__DisplayClass2_0.<<Main>b__0>d.MoveNext()
Unable to start Microsoft.Dnx.TestHost
========== Discover test finished: 0 found (0:00:01.057196) ==========
My solution DNX SDK version, according to both projects' properties window, is 1.0.0-rc1-update1. I also set that as the "active" runtime via dnvm, with no change in the above behavior. I don't understand the instructions about running DNX from the command line, though, so perhaps that's a starting point?
When I try switching DNX SDK to 1.0.0-beta5, instead, and clean solution, I get:
------ Discover test started ------
------ Test started: Project: MyProjectTest ------
Starting Microsoft.Framework.TestHost [C:\Users\xxxxx\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta5\bin\dnx.exe --appbase "C:\Users\xxxxxx\Documents\GitForWindows\Repositories\MySolution\MyProjectTest" Microsoft.Framework.ApplicationHost --port 9737 Microsoft.Framework.TestHost --port 9770 --parentProcessId 16732]
System.InvalidOperationException: Failed to resolve the following dependencies for target framework 'DNX,Version=v4.5.1':
xunit 2.1.0
xunit.runner.dnx 2.1.0-beta6-build191
Searched Locations:
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\{name}\project.json
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\src\{name}\project.json
C:\Users\xxxxx\Documents\GitForWindows\Repositories\MySolution\test\{name}\project.json
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\{name}.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_32\{name}\{version}\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_64\{name}\{version}\{name}.dll
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\{name}\{version}\{name}.dll
Try running 'dnu restore'.
at Microsoft.Framework.Runtime.DefaultHost.GetEntryPoint(String applicationName)
at Microsoft.Framework.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args)
at Microsoft.Framework.ApplicationHost.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Framework.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
at dnx.host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env)
at dnx.host.RuntimeBootstrapper.ExecuteAsync(String[] args)
at dnx.host.RuntimeBootstrapper.Execute(String[] args)
Unable to start Microsoft.Framework.TestHost
========== Discover test finished: 0 found (0:00:01.4699978) ==========
Running DNU restore doesn't resolve anything.
EDIT: Here's the project.json as requested:
{
"version": "1.0.0-*",
"description": "",
"authors": [ "" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"xunit": "2.1.0",
"xunit.runner.dnx": "2.1.0-beta6-build191"
},
"commands": {
"test": "xunit.runner.dnx"
},
"frameworks" : {
"dnx451": { },
"dnxcore50" : {
"dependencies": {
"System.Collections": "4.0.11-beta-23225",
"System.Linq": "4.0.1-beta-23225",
"System.Threading": "4.0.11-beta-23225",
"Microsoft.CSharp": "4.0.1-beta-23225"
}
}
}
}

You need to use a version of xUnit runner that matches dnx. For dxn RC1 you need to use the version 2.1.0-rc1-build204 of xunit.runner.dnx

Related

Unit Tests not discovered and executed in Visual Studio 2017 when legacy test settings specified

I'm using Visual Studio 2017 Professional 15.4.5 and I found out unit tests will not be discovered when legacy .testsettings is loaded via selecting it in the Test > Test Settings > Select Test Settings menu
Here are steps to reproduce it:
Create a new Solution
Create a Class Library project with target framework .NET Framework 4.5.2 with following simple class:
public class Class1
{
public bool True => true;
}
Create a Unit Test Project(.Net Framework) with target framework .NET Framework 4.5.2 and setup project reference and write a simple test:
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
Assert.IsTrue(new Class1().True);
}
}
Run the test, the test should be discovered and run
Use solution context menu to select Add > New Item, select Test Settings in the left pane and select Test Settings in the middle to create a new test settings.
Skip the setting by just closing the dialog. Set the test settings by clicking the menu Test > Test Settings > Select Test Settings
Run the test again, it was not executed and some information can be seen in the Output pane:
[2017/12/08 13:36:20 Informational] ------ Run test started ------
[2017/12/08 13:36:22 Warning] Warning : A testsettings file or a runsettings with a ForcedLegacyMode set to true is not supported with the MSTest V2 Adapter.
[2017/12/08 13:36:22 Error] Test adapter sent back a result for an unknown test case. Ignoring result for 'TestMethod1'.
[2017/12/08 13:36:22 Informational] ========== Run test finished: 0 run (0:00:01.9851985) ==========
Updates
To answer #aruna I followed my own instructions again with VS2017 Professional 15.5.7
The test still failed to run but the output is different:
[2018/03/01 13:39:13 Informational] ------ Load Playlist started ------
[2018/03/01 13:39:13 Informational] ========== Load Playlist finished (0:00:00.001) ==========
[2018/03/01 13:40:46 Informational] ------ Discover test started ------
[2018/03/01 13:40:48 Informational] ========== Discover test finished: 1 found (0:00:02.1855628) ==========
[2018/03/01 13:40:48 Informational] ------ Run test started ------
[2018/03/01 13:40:49 Informational] ========== Run test finished: 1 run (0:00:01.5406918) ==========
[2018/03/01 13:41:32 Informational] ------ Run test started ------
[2018/03/01 13:41:34 Warning] Warning : A testsettings file or a runsettings with a ForcedLegacyMode set to true is not supported with the MSTest V2 Adapter.
[2018/03/01 13:41:34 Warning] No test is available in D:\git\demo\unit-test-legacy-settings\UnitTestProject1\bin\Debug\UnitTestProject1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[2018/03/01 13:41:34 Informational] ========== Run test finished: 0 run (0:00:02.0727927) ==========

Build of project fails on Visual Studio Team Services - missing lock file

I am trying to configure CI for my team project, however, my build doesn't get past the first library project. It is complaining about missing the lock file. I have configured nugget to restore but that doesn't seem to create the lock file. Git ignores the lock file so it is not put in repository.
Summary
| Build
3 error(s), 0 warning(s)
Build - 3 error(s), 0 warning(s)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(241):Project Core does not have a lock file.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(241):Project Core does not have a lock file.
Process 'msbuild.exe' exited with code '1'.
| Finalize build
0 error(s), 0 warning(s)
Does anyone know how to force build to create the lock file?
My solution is an ASP.NET Core RC2 website. It builds fine on VS 2015. Microsoft announce ASP.NET Core last week so it should be on the build servers, or do I have to create my own build server?
Here is the contents of my project.json file for the Core Library:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNetCore.Identity": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
"Microsoft.EntityFrameworkCore": "1.0.0-rc2-final",
"Microsoft.Extensions.Caching.Abstractions": "1.0.0-rc2-final",
"Microsoft.Extensions.Logging": "1.0.0-rc2-final",
"NETStandard.Library": "1.5.0-rc2-24027",
"NodaTime": "2.0.0-alpha20160523"
},
"frameworks": {
"netstandard1.5": {
"dependencies": {
"System.ComponentModel.Annotations": "4.1.0-rc2-24027"
},
"imports": [ "dnxcore50", "portable-net45+win8" ]
}
}
}
You can solve this by adding a new build step to your build definition.
Add a 'Command Line' task as step 1 of your build definition.
The settings for this task are:
Tool: dotnet
Arguments: restore
You can also speed this up a little by adding the following variable to your build definition:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE = true

Unable to load application or execute command 'Microsoft.Dnx.TestHost'. Available commands: test

Trying to test an ASPNET 5 application in VS2015.
{
"version": "1.0.0-*",
"description": "HoldingTank Class Library",
"dependencies": {
"EntityFramework.InMemory": "7.0.0-rc1-final",
"FluentAssertions": "4.1.1",
"GenFu": "1.0.4",
"MyMVCProject": "1.0.0-*",
"xunit": "2.1.0",
"xunit.runner.visualstudio": "2.1.0"
},
"commands": {
"test": "xunit.runner.dnx"
},
"frameworks": {
"dnx451": { }
}
}
However, no tests show up in the Test Explorer window and when I hit F5 I get:
------ Discover test started ------
------ Test started: Project: HoldingTank ------
Starting Microsoft.Dnx.TestHost [C:\Users\erik\.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin\dnx.exe --appbase "C:\code\PortalSolution\src\HoldingTank" Microsoft.Dnx.ApplicationHost --port 52620 Microsoft.Dnx.TestHost --port 56351 --parentProcessId 8368]
Error: Unable to load application or execute command 'Microsoft.Dnx.TestHost'. Available commands: test.
Unable to start Microsoft.Dnx.TestHost
========== Discover test finished: 0 found (0:00:01.8238001) ==========
I just have one test, decorated with [Fact] but it doesn't look like it is getting that far.
Looking at similar questions that have "unable to load" errors (but couldn't find any specific to TestHost), I've tried making sure that both the test project and the application target the same frameworks, but couldn't find any discrepancies. And I don't see anything in the Event Log.
Any suggestions? - not even sure where to go to start to troubleshoot this.
You have to add the "xunit.runner.dnx" as dependency instead of the "xunit.runner.visualstudio". Then it will work in VisualStudio.
Since ASP.Net 5 is in beta, so is xunit.runner.dnx. Use the current pre-release which matches ASP.Net RC1 ... I currently use 2.1.0-rc1-build204 with ASP.Net 5 RC1

gumbo-d bindings with DUB

I'm trying to use gumbo-d in a project however dub is failing.
Here's the dub output:
Building: myproject (Default)
Performing main compilation...
dub build "myproject" "--build=plain"
Building package myproject in C:\Users\Matt\Documents\Projects\myproject\
Target vibe-d 0.7.23 is up to date. Use --force to rebuild.
Target gumbo-d 0.2.2 is up to date. Use --force to rebuild.
Building myproject ~master configuration "application", build type plain.
Compiling using dmd...
Linking...
OPTLINK (R) for Win32 Release 8.00.15
Copyright (C) Digital Mars 1989-2013 All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
..\..\..\AppData\Roaming\dub\packages\gumbo-d-0.2.2\gumbo-d.lib(parse)
Error 42: Symbol Undefined _gumbo_destroy_output
..\..\..\AppData\Roaming\dub\packages\gumbo-d-0.2.2\gumbo-d.lib(parse)
Error 42: Symbol Undefined _gumbo_parse
--- errorlevel 2
FAIL .dub\build\application-plain-windows-x86-dmd_2066-946D41E793C045166B4DFD37035481AE\ myproject executable
Error executing command build: dmd failed with exit code 2.
Exit code 2
Build complete -- 1 error, 0 warnings
---------------------- Done ----------------------
Build: 1 error, 0 warnings
I'm at a bit of a loss of where the library file needs to go and what format it needs to be in. There is a .lib file in the gumbo-d dependency directory, is this meant to be the library? If so, why is the linker failing to link to it?
Here is the contents of my main dub.json file (for the overall project which includes the gumbo-d dependency)
{
"name": "googleplayscraper",
"description": "A simple vibe.d server application.",
"copyright": "Copyright © 2015, Matt",
"authors": ["Matt"],
"dependencies": {
"vibe-d": "~>0.7.19",
"gumbo-d": "~>0.2.2"
},
"versions": ["VibeDefaultMain"]
}
And here is the dub.json file for the gumbo-d dependency:
{
"libs-posix": [
"gumbo"
],
"version": "0.2.2",
"description": "D bindings for Google's Gumbo HTML5 parser library",
"authors": [
"Christopher Bertels"
],
"importPaths": [
"source/"
],
"configurations": [
{
"targetType": "library",
"name": "library"
}
],
"homepage": "https://github.com/bakkdoor/gumbo-d",
"sourcePaths": [
"source/"
],
"name": "gumbo-d",
"copyright": "Copyright © 2013, Christopher Bertels"
}

Experiencing "DEP3000" error when trying to run WinRT unit tests

I am experience this strange error trying to run unit tests for WinRT from Visual Studio 2012.
Error: DEP3000: Attempts to stop the application failed. This may
cause the deployment to fail. App Packages may only be shutdown as
part of a Visual Studio build operation
I don't understand at all what that could mean? I've tried restarting my computer and reinstalling developer license. How I reproduce it is I just create a new empty unit test project from the Visual Studio template. I don't touch the project at all. But, when I try to do Run Tests on it, it just says pending for a a while and then spits out that error
How do I fix this?
Specs: Windows 8 Enterprise 64bit, Visual Studio 2012 with Update 2
Also, I've seen this question about VS2012RC, but the answer doesn't seem to apply. I've tried every configuration of this there is and nothing works past this error
I had same problem when I applied VS upgrade2 AND used Resharper 7.1.1 to run the unittests. Turns out you need to upgrade Resharper to 7.1.3 -- or run the tests with the VS test explorer.
You can just try using XUnits App:
https://channel9.msdn.com/Shows/demooftheday/xunit-in-uwp
With this, test will run on XUnit's test app, not in VS Test Explorer.
In my unit test project's project.json
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"xunit": "2.1.0",
"xunit.runner.devices": "2.1.0" }, "frameworks": {
"uap10.0": { } }, "runtimes": {
"win10-arm": { },
"win10-arm-aot": { },
"win10-x86": { },
"win10-x86-aot": { },
"win10-x64": { },
"win10-x64-aot": { } }
}
Then go to the XAML file in the unit test project named UnitTestapp.xaml and change it to
<ui:RunnerApplication
x:Class="UnitTestProject1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UnitTestProject1"
xmlns:ui="using:Xunit.Runners.UI"
RequestedTheme="Light">
</ui:RunnerApplication>
And of course, in the code behind:
sealed partial class App : RunnerApplication
{
protected override void OnInitializeRunner()
{
AddTestAssembly(GetType().GetTypeInfo().Assembly);
InitializeRunner();
}
partial void InitializeRunner();
}