C# TestMethod未在c中运行#
我有以下测试课程:C# TestMethod未在c中运行#,c#,.net,testing,integration-testing,C#,.net,Testing,Integration Testing,我有以下测试课程: using System; using DDDSample1.Domain.DriverDuties; using DDDSample1.Domain.Shared; using DDDSample1.Controllers; using System.Collections.Generic; using Moq; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace IntegrationTests {
using System;
using DDDSample1.Domain.DriverDuties;
using DDDSample1.Domain.Shared;
using DDDSample1.Controllers;
using System.Collections.Generic;
using Moq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace IntegrationTests
{
public class DriverDutyControllerTest
{
[TestMethod]
public async void GetByIdTest()
{
var repo = new Mock<IDriverDutyRepository>();
var unitOfWork = new Mock<IUnitOfWork>();
var service = new DriverDutyService(unitOfWork.Object, repo.Object);
var controller = new DriverDutiesController(service);
DriverDutyId id = new DriverDutyId("id1");
string key = "keyDD1";
string driver = "DriverDD";
List<String> workblocks = new List<String>();
workblocks.Add("wb1");
workblocks.Add("wb2");
workblocks.Add("wb3");
var ddDto = new CreatingDriverDutyDto(key, driver, workblocks.ToArray());
var dd = new DriverDuty(key, driver, workblocks);
repo.Setup(_ => _.AddAsync(dd)).ReturnsAsync(dd);
var actual = await controller.GetGetById(id.AsGuid());
Console.WriteLine(actual.Value);
Assert.IsTrue(true);
}
}
}
为什么我的测试会被跳过?有没有办法解决这个问题
注意:我正在开发层(在本例中为控制器和服务)之间的集成测试,因此我需要模拟这些层,因为我不想访问数据库。尝试将签名从
async void
更改为async Task
:
[TestMethod]
public async Task GetByIdTest()
...
测试运行人员不能等待返回的void
方法
此外,该类还应使用[TestClass]
属性修饰:
[TestClass]
public class DriverDutyControllerTest
...
尝试将签名从
async void
更改为async Task
:
[TestMethod]
public async Task GetByIdTest()
...
测试运行人员不能等待返回的void
方法
此外,该类还应使用[TestClass]
属性修饰:
[TestClass]
public class DriverDutyControllerTest
...