Xunit 测试测试资源管理器未 运行 测试

Xunit testing test explorer not running tests

嘿,我正在阅读有关 c# 中的单元测试的教程,但我没有让 Testexplorer 运行 我的测试。它一直告诉我有测试,但它们没有得到 运行ned。我基本上已经尝试了一切感觉所以我在这里问!为什么我的测试没有 运行ning 是 vs 中的错误还是只是我遗漏了一些愚蠢的东西?我将使用 im 发送教程,但他显示了 .net 框架,我知道我需要对 .net 核心使用 .net 核心测试等等,所以这里是教程 https://www.youtube.com/watch?v=ub3P8c87cwk&t=1001s,这是我的代码...

测试Class

using System;
using Gradebook;
using Xunit;
 

namespace GradeBook.Tests
{
    public class BookTests
    {

       [Fact]
        public void Test1()
        {
            // arrange
            var book = new Book("");

            // act
            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.3);

            var result = book.GetStatistics();
            // assert
            Assert.Equal(85.6, result.Average, 1);
            Assert.Equal(90.5, result.High, 1);
            Assert.Equal(77.3, result.Low, 1);

        }


    }
}

Class 正在测试

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gradebook
{

    public class NamedObject
    {

        public string Name { get; set; }
        public NamedObject(string name)
        {
            Name = name;
        }



    }


    public abstract class BookBase : NamedObject
    {
        protected BookBase(string name) : base(name)
        {
        }
        public abstract void AddGrade(double grade); 
    }



    public class Book : BookBase
    {
        List<double> grades { get; set; }
        public Book(string name) : base(name)
        {
            grades = new List<double>();
            this.Name = name; 
        }

        public override void AddGrade(double grade)
        {
            if(grade <= 100 && grade >= 0)
            {
                grades.Add(grade); 
            }
        }
        public Statistics GetStatistics()
        {
            var result = new Statistics();
            result.High = double.MinValue; 
            result.Low = double.MaxValue;

            foreach (var grade in grades)
            {
                result.Low = Math.Min(grade, result.Low);
                result.High = Math.Max(grade, result.High);
                result.Average += grade; 
            }
            result.Average /= grades.Count;

            return result;







        }



    }
}

主要

using System;
using System.Collections.Generic;

namespace Gradebook
{
    class Program
    {
        //Double is twice as precise as float. Though takes more memmory.
        static void Main(string[] args)
        {

            var book = new Book("Jens's Grade Book");
            book.AddGrade(89.1);
            book.AddGrade(90.5);
            book.AddGrade(77.5);

            var stats = book.GetStatistics();

            Console.WriteLine($"The lowest grade is {stats.Low}");
            Console.WriteLine($"The highest grade is {stats.High}");
            Console.WriteLine($"The average grade is {stats.Average: N1}");







        }
        private static void EnterGrades(Book book)
        {
            while (true)
            {
                Console.Write("Enter a grade or press 'q' to quit: ");
                var input = Console.ReadLine();
                if(input == "q")
                {
                    break;
                }
                try
                {
                    var grade = double.Parse(input);
                    book.AddGrade(grade); 
                }
                catch(ArgumentException ex) 
                {
                    Console.WriteLine(ex.Message);
                }
                catch(FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                finally
                {
                    Console.WriteLine("**");
                }
            }

        }
        public void useLessCode()
        {
            //float x;
            //float y;
            //x = 34.1F;
            //y = 34.6F;
            //var result = x + y;
            //Console.WriteLine(result.ToString());

            //Arrays are static until used function Resize...

            //var numbers = new[] { 12.7F, 10.3F, 6.11F, 4.1F };
            //float result = new float(); 
            //foreach(var number in numbers)
            //{
            //    result += number; 
            //}
            //Console.WriteLine(result);
            //numbers[0] = 12.7F;
        }


    }
}

统计数据class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gradebook
{
    public class Statistics
    {
        public double Average;
        public double High;
        public double Low; 



    }
}

我的代码编辑器的图片,这样您就可以看到我的参考资料和包

从 nuget 包管理器安装 Microsoft.NET.Test.Sdk 包解决了我的问题。