Xamarin Android Nunit测试可在测试浏览器中发现,但在运行测试时未发现。 (VS2017)

时间:2019-03-18 11:38:42

标签: android unit-testing xamarin visual-studio-2017 nunit

正如标题所示,我正在尝试为我的使用Xamarin.Android的Android应用程序创建一些测试。按照步骤here,我已经下载了Nunit VS模板并创建了NUnit 3测试项目(Android)。

我可以在测试浏览器中看到默认测试,但是如果尝试运行测试,则会在输出窗口中看到以下内容:

[18/03/2019 11:24:21 Informational] ------ Discover test started ------
[18/03/2019 11:24:25 Warning] No test is available in C:\Project\NUnit.Tests.Droid1\NUnit.Tests.Droid1.csproj C:\Project\Springboard Warehouse\Springboard Warehouse.csproj. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[18/03/2019 11:24:25 Informational] ========== Discover test finished: 0 found (0:00:04.1467419) ==========
[18/03/2019 11:24:51 Informational] ------ Discover test started ------
[18/03/2019 11:24:53 Warning] No test is available in C:\Project\NUnit.Tests.Droid1\NUnit.Tests.Droid1.csproj C:\Project\Springboard Warehouse\Springboard Warehouse.csproj. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[18/03/2019 11:24:53 Informational] ========== Discover test finished: 0 found (0:00:01.6753664) ==========
[18/03/2019 11:24:53 Informational] ------ Discover test started ------
[18/03/2019 11:24:54 Informational] NUnit Adapter 3.13.0.0: Test discovery starting
[18/03/2019 11:24:54 Warning] Exception NUnit.Engine.NUnitEngineException, Exception thrown discovering tests in C:\Project\NUnit.Tests.Droid1\bin\Debug\NUnit.Tests.Droid1.dll
[18/03/2019 11:24:54 Warning] The NUnit 3 driver cannot support this test assembly. Use a platform specific runner.
[18/03/2019 11:24:54 Warning]    at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
   at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
   at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
   at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
   at NUnit.Engine.Runners.DirectTestRunner.Explore(TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
   at NUnit.VisualStudio.TestAdapter.NUnit3TestDiscoverer.DiscoverTests(IEnumerable`1 sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestDiscoverer.cs:line 96
[18/03/2019 11:24:54 Warning] Innerexception: System.Runtime.Serialization.SerializationException: Type 'NUnit.Framework.Api.FrameworkController' in assembly 'nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb' is not marked as serializable.
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
[18/03/2019 11:24:54 Informational] NUnit Adapter 3.13.0.0: Test discovery complete
[18/03/2019 11:24:54 Informational] NUnit VS Adapter 2.1.1.0 discovering tests is started
[18/03/2019 11:24:54 Warning] Dependent Assembly Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065 of C:\Project\NUnit.Tests.Droid1\bin\Debug\NUnit.Tests.Droid1.dll not found. Can be ignored if not a NUnit C:\Project.
[18/03/2019 11:24:54 Warning] Dependent Assembly Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065 of C:\Project\Springboard Warehouse\bin\Debug\Springboard Warehouse.dll not found. Can be ignored if not a NUnit C:\Project.
[18/03/2019 11:24:54 Informational] NUnit VS Adapter 2.1.1.0 discovering test is finished
[18/03/2019 11:24:54 Warning] No test is available in C:\Project\NUnit.Tests.Droid1\bin\Debug\NUnit.Tests.Droid1.dll C:\Project\Springboard Warehouse\bin\Debug\Springboard Warehouse.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[18/03/2019 11:24:54 Informational] ========== Discover test finished: 0 found (0:00:01.6691257) ==========
[18/03/2019 11:25:31 Informational] ------ Run test started ------
[18/03/2019 11:25:32 Informational] NUnit Adapter 3.13.0.0: Test execution started
[18/03/2019 11:25:32 Informational] Running all tests in C:\Project\NUnit.Tests.Droid1\bin\Debug\NUnit.Tests.Droid1.dll
[18/03/2019 11:25:33 Warning] Exception NUnit.Engine.NUnitEngineException, Exception thrown executing tests
[18/03/2019 11:25:33 Warning] The NUnit 3 driver cannot support this test assembly. Use a platform specific runner.
[18/03/2019 11:25:33 Warning]    at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
   at NUnit.Engine.Runners.DirectTestRunner.LoadDriver(IFrameworkDriver driver, String testFile, TestPackage subPackage)
   at NUnit.Engine.Runners.DirectTestRunner.LoadPackage()
   at NUnit.Engine.Runners.TestDomainRunner.LoadPackage()
   at NUnit.Engine.Runners.DirectTestRunner.EnsurePackageIsLoaded()
   at NUnit.Engine.Runners.DirectTestRunner.Explore(TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.Explore(TestFilter filter)
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath, TestFilter filter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 310
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 103
[18/03/2019 11:25:33 Warning] Innerexception: System.Runtime.Serialization.SerializationException: Type 'NUnit.Framework.Api.FrameworkController' in assembly 'nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb' is not marked as serializable.
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityAttributes)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.CreateObject(String typeName, Object[] args)
   at NUnit.Engine.Drivers.NUnit3FrameworkDriver.Load(String testAssemblyPath, IDictionary`2 settings)
[18/03/2019 11:25:33 Informational] NUnit Adapter 3.13.0.0: Test execution complete
[18/03/2019 11:25:33 Informational] NUnit VS Adapter 2.1.1.0 executing tests is started
[18/03/2019 11:25:33 Warning] Dependent Assembly Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065 of C:\Project\NUnit.Tests.Droid1\bin\Debug\NUnit.Tests.Droid1.dll not found. Can be ignored if not a NUnit C:\Project.
[18/03/2019 11:25:33 Informational] NUnit VS Adapter 2.1.1.0 executing tests is finished
[18/03/2019 11:25:33 Warning] No test is available in C:\Project\NUnit.Tests.Droid1\bin\Debug\NUnit.Tests.Droid1.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
[18/03/2019 11:25:33 Informational] ========== Run test finished: 0 run (0:00:01.7390314) ==========

我从nuget安装了NUnit v3.11.0,nunit.xamarin v3.6.1和Nunit3TestAdapter v3.13.0,以及Nunit 3测试适配器扩展。有什么想法可能导致此问题吗?

1 个答案:

答案 0 :(得分:1)

NUnit测试适配器不支持在Visual Studio测试运行器中运行Android测试。 (我认为这是VS测试运行程序的局限性,但我对此不是100%肯定!)

您应该改为在模拟器或设备上将NUnit.Tests.Droid1作为Android应用程序启动。该应用程序将是GUI测试运行程序,可让您运行测试。

看起来会像这样:

enter image description here

另一件事-您的应用程序应引用与nunit.xamarin相同的NUnit版本-因此,您确实想引入NUnit 3.6.1,而不是NUnit 3.11。计划将来改变!