English 中文(简体)
• 如何将XUnit项目添加到......。 NET 7 MAUI解决方案?
原标题:How to add an xUnit project to .NET 7 MAUI solution?

I want to run unit tests on my view models, services, etc. on my .NET 7 MAUI app. I following this, but it s for .NET 6 so I found this which is for .NET 7 but it seems both use the same process. Anyway, I followed the steps after adding net7.0 to my target framework, all my nuget packages get removed and when trying to build, I get these errors: error NETSDK1005: Assets file C:...projectobjproject.assets.json doesn t have a target for net7.0 . Ensure that restore has run and that you have included net7.0 in the TargetFrameworks for your project.

error NU1201:项目与净额7.0(NETCoreApp,Version=v7.0)不兼容。 项目不支持任何目标框架。

main project: <TargetFrameworks>net7.0;net7.0-android33.0</TargetFrameworks> <OutputType Condition=" $(TargetFramework) != net7.0 ">Exe</OutputType>

xUnit project: <TargetFramework>net7.0</TargetFramework>

有人建议卸载/重载我的项目,重新启用演播室视觉,我尝试了这种视力,但没有奏效。 我如何确定这一点?

问题回答

The solution was found and presented by Gerald Versluis in his video

Unit Testing .NET MAUI Apps with xUnit

摘要:

  • On your MAUI project, add a core .Net target. My example is with .Net 8 but his is .Net 6, so this should work for any .Net core version. I am adding "net8.0" at the beginning:

以前

<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>

之后

<TargetFrameworks>net8.0;net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
  • Then we need, in the same project file, the output to be a Library in order to be consumed by the tests, but only when the target is the core framework.

以前

<OutputType>Exe</OutputType>

之后

<OutputType Condition=" $(TargetFramework)  !=  net8.0 ">Exe</OutputType>

第一答案是巨大的。 只是想补充一点。 不要改变应用分类,它必须是1或1.0,否则解决办法就没有工作。 因为bug





相关问题
run unit tests and coverage in certain python structure

I have some funny noob problem. I try to run unit tests from commandline: H:PROpyEstimator>python src estpython est_power_estimator.py Traceback (most recent call last): File "src est...

How to unit-test an enterprise symfony project?

I´m working on a huge project at my work. We have about 200 database tables, accordingly a huge number of Models, Actions and so on. How should I begin to write tests for this? My biggest problem ...

Code Coverage Tools & Visual Studio 2008 Pro

Just wondering what people are using for code coverage tools when using MS Visual Studio 2008 Pro. We are using the built-in MS test project and unit testing tool (the one that come pre-installed ...

Unit testing. File structure

I have a C++ legacy codebase with 10-15 applications, all sharing several components. While setting up unittests for both shared components and for applications themselves, I was wondering if there ...

Unit Testing .NET 3.5 projects using MStest in VS2010

There s a bug/feature in Visual Studio 2010 where you can t create a unit test project with the 2.0 CLR. https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483891&wa=...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...