[[oktatas:programozás:csharp:dotnetcore|< .Net Core]] ====== .Net Core Xunit ====== * **Szerző:** Sallai András * Copyright (c) Sallai András, 2022 * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] * Web: https://szit.hu ===== Szükséges ===== Bővítmények Visual Studio Code programnak: * C# for Visual Studio Code (powered by OmniSharp) Microsoft * NuGet Package Manager ===== Projekt kezdés ===== mkdir app01 cd app01 dotnet new console code . ===== Program fejlesztése ===== class Triangle { public double calcArea(double basea, double height) { return basea * height / 2; } } ===== Teszt fejlesztése ===== using Xunit; public class TriangleTest { [Fact] public void calcAreaTest() { Triangle tri = new Triangle(); double res = tri.calcArea(30, 35); Assert.Equal(525, res); } } ===== NuGet ===== Három csomagot kell hivatkozni. Jelenítsük meg a parancs panelt. * F1 * NuGet Package Manager: Add Package * Microsoft.NET.Test.Sdk * xunit * xunit.runner.visualstudio Vegyük fel az app01.csproj fájlban: false Ha jól csináltuk az app01.csproj fájl tartalma: Exe net6.0 false enable enable ===== Teszt futtatása ===== dotnet test Lehetséges eredmény: dotnet test Determining projects to restore... All projects are up-to-date for restore. app01 -> /home/janos/dev/dotnet/app01/bin/Debug/net6.0/app01.dll Test run for /home/janos/dev/dotnet/app01/bin/Debug/net6.0/app01.dll (.NETCoreApp,Version=v6.0) Microsoft (R) Test Execution Command Line Tool Version 17.0.0 Copyright (c) Microsoft Corporation. All rights reserved. Starting test execution, please wait... A total of 1 test files matched the specified pattern. Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: < 1 ms - /home/janos/dev/dotnet/app01/bin/Debug/net6.0/app01.dll (net6.0)