Probleme mit Unit -Test/Integration .NET 8 ProjektC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Probleme mit Unit -Test/Integration .NET 8 Projekt

Post by Anonymous »

Ich habe Probleme mit dem Versuch, Unit -Tests /-integration mit .NET 8 zu einem Projekt durchzuführen (kleine API, die funktioniert). Ich wollte Tests hinzufügen, um zu lernen, da ich sie noch nie gemacht habe, aber ich stoße auf etwas, das ich nicht lösen kann. (WebAPI.Tests/)
Ich habe den Ordner webapi.tests im Hauptprojekt hinzugefügt (ich weiß nicht, ob dies die richtige Praxis ist). Wenn ich es ausführe, erhalte ich Fehler wie doppelte Attribute und fehlende Pakete wie Xunit, FactatTribute, Fakt.

Code: Select all

/DotNetProjects/WebApi/WebApi.Tests$ dotnet list package --outdated

The following sources were used:
https://api.nuget.org/v3/index.json

Project `WebApi.Tests` has the following updates to its packages
[net8.0]:
Top-level Package                    Requested   Resolved   Latest
> coverlet.collector                 6.0.0       6.0.0      6.0.4
> Microsoft.NET.Test.Sdk             17.6.0      17.6.0     17.13.0
> xunit                              2.6.3       2.6.3      2.9.3
> xunit.core                         2.6.3       2.6.3      2.9.3
> xunit.extensibility.core           2.6.3       2.6.3      2.9.3
> xunit.extensibility.execution      2.6.3       2.6.3      2.9.3
> xunit.runner.visualstudio          2.4.5       2.4.5      3.0.2
< /code>
Die seltsame Sache ist, dass ich, wenn ich mein Testprojekt ohne Verweis auf das Hauptprogramm ausführeDotNetProjects/WebApi/WebApi.Tests$ dotnet test
Determining projects to restore...
All projects are up-to-date for restore.
/home/gustavo.ruiz/DotNetProjects/WebApi/obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs(4,12): error CS0579: Duplicate 'global::System.Runtime.Versioning.TargetFrameworkAttribute' attribute [/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.csproj]
/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.Tests/GlobalUsings.cs(1,14): error CS0246: The type or namespace name 'Xunit' could not be found (are you missing a using directive or an assembly reference?) [/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.csproj]
/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.Tests/UnitTest1.cs(5,6): error CS0246: The type or namespace name 'FactAttribute' could not be found (are you missing a using directive or an assembly reference?) [/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.csproj]
/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.Tests/UnitTest1.cs(5,6): error CS0246: The type or namespace name 'Fact' could not be found (are you missing a using directive or an assembly reference?) [/home/gustavo.ruiz/DotNetProjects/WebApi/WebApi.csproj]
< /code>
Webapi.csproj:


net8.0
enable
enable
false







runtime; build; native; contentfiles; analyzers; buildtransitive
all





< /code>
Webapi.tests.csproj:



net8.0
enable
enable

false
true









runtime; build; native; contentfiles; analyzers; buildtransitive
all


runtime; build; native; contentfiles; analyzers; buildtransitive
all









< /code>
Wie ich bei der Entfernung von Projectreference kommentierte, wird die Tests ohne Probleme ausgeführt (obwohl es praktisch nur das Testprojekt erstellt hat und einen Beispielcode hat) < /p>
 unittEst1.cs:
namespace WebApi.Tests;

public class UnitTest1
{
[Fact]
public void Test1()
{
Assert.True(true);
}
}
Things I have tried:

[*]Delete the project and recreate it (dotnet new xunit -n WebApi.Tests -o WebApi.Tests)
[*]Delete the bin and obj directories and run dotnet restore, dotnet clean, dotnet Build
Installieren Sie die Testpakete erneut>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post