简体   繁体   中英

Async unit tests are not visible in Visual Studio

I use Visual Studio 2015 Ultimate, I wrote some unit test (I use xUnit 2.1.0.3179, it allow for this signature):

public async Task MyTest()

instead of standard unit test signature

public void MyTest()

but these unit tests are not visible in Visual Studio (code lens) and in Test Explorer. Of course I rebuild solution without any error :)

在此处输入图片说明

Is there any possibility to have the same feature like tests with standard signature? Maybe there is any VS extension?

I'm pretty sure that you might've found a solution for this already, but I found your question while I was trying to fix my async unit test. (Note: I'm using the latest Visual Studio 2015 Update 3).

   [TestMethod]
    public async Task GetVendors_ByRegionId_ReturnFilteredVendors()
    {
        // Arrange
        var optionsBuilder = new DbContextOptionsBuilder();
        optionsBuilder.UseSqlServer("Server=server12345;Database=DB789;Trusted_Connection=True;MultipleActiveResultSets=true");
        var ctx = new ApplicationDbContext(optionsBuilder.Options);
        ILoggerFactory logFac = new LoggerFactory();
        ILogger<VendorRepository> loggerRepository = new Logger<VendorRepository>(logFac);
        IVendorRepository vendRepo = new VendorRepository(ctx, loggerRepository);

        // Act
        Task<List<Vendor>> resultTask = vendRepo.GetVendors(1);
        IList<Vendor> vendorList = await resultTask;

        // Assert
        Assert.IsNotNull(vendorList);
        Assert.IsTrue(vendorList.Count > 10);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM