完成后单元测试中的元素未决 [英] Element in unit tests left pending after completion

查看:39
本文介绍了完成后单元测试中的元素未决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行测试后,我在 Resharper 中看到此警告,所有测试均通过.

I'm seeing this warnings in Resharper after running tests, all the tests pass.

2018.08.09 11:11:58.524 WARN 元素 Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests 被留下运行完成后挂起.2018.08.09 11:11:58.524 WARN 元素 Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests.Reso 被留下运行完成后挂起.

2018.08.09 11:11:58.524 WARN Element Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests was left pending after its run completion. 2018.08.09 11:11:58.524 WARN Element Data.Tests.Infra.IntegrationTests.ResolvedIdentityTests.Reso was left pending after its run completion.

它们是在测试数据库中设置一些 sql 的集成测试,然后针对该数据库运行测试.

They are integration tests that setup some sql in a test database, then tests are run against that database.

这是完整的测试类:

namespace Data.Tests.Infra.IntegrationTests
{
    using System;
    using System.Data.SqlClient;
    using System.Threading.Tasks;
    using Dapper;
    using Infrastructure.Models;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public sealed class ResolvedIdentityTests
    {
        [ClassInitialize]
        public static void Initialise(TestContext context)
        {
            const string sql = @"insert into infra.tblUnresolvedIdentities
                                (DeviceId, Fqdn, TimeConflictOccured)
                                values
                                ('85E33FB5-C321-4EF2-994C-C835F136BA0C', 'unr.test.foo', '2018-08-06 12:16:24.183'),
                                ('D3F32F97-2375-47CC-86E7-37C50ABAC85F', 'unr2.test.foo', '2018-08-06 12:16:24.183')

                                insert into infra.tblOrg ([Name]) values ('rito')
                                declare @orgId int = (select OrgId from infra.tblOrg where [Name] = 'rito');

                                insert into infra.tblSite ([SiteName], [OrgId]) values ('rito.site', @OrgId);
                                declare @siteId int = (select SiteId from infra.tblSite where [SiteName] = 'rito.site');

                                insert into infra.tblDevice
                                (DeviceId, [Name], SiteId)
                                values
                                ('CE810507-C614-4C65-9675-569EEFFDBC9F', 'unr.test.foo', @siteId),
                                ('94FF1C23-0B7E-41CB-A0F8-058CED0465B3', 'blacklisted.test.foo', @siteId)

                                insert into infra.tblBlacklistedAgents
                                (DeviceId, Fqdn)
                                values
                                ('94FF1C23-0B7E-41CB-A0F8-058CED0465B3', 'rit.test.com')";
            RunSql(sql);
        }

        [ClassCleanup]
        public static void Cleanup()
        {
            const string sql = @"delete from infra.tblBlacklistedAgents where DeviceId = '94FF1C23-0B7E-41CB-A0F8-058CED0465B3'
                                 delete from infra.tblUnresolvedIdentities where DeviceId in ('85E33FB5-C321-4EF2-994C-C835F136BA0C', 'D3F32F97-2375-47CC-86E7-37C50ABAC85F')
                                 delete from infra.tblDevice where DeviceID in( 'CE810507-C614-4C65-9675-569EEFFDBC9F', '94FF1C23-0B7E-41CB-A0F8-058CED0465B3')
                                 delete from infra.tblsite where SiteName = 'rito.site'
                                 delete from infra.tblorg where Name = 'rito'
                                 delete from infra.tblResolvedIdentities where ActualDeviceId = 'CE810507-C614-4C65-9675-569EEFFDBC9F'";
            RunSql(sql);
        }

        private static void RunSql(string sql)
        {
            using (var sqlConnection = new SqlConnection(Configuration.InitConfiguration()["ConnectionString"]))
                sqlConnection.Execute(sql);
        }

        [TestMethod]
        public async Task ResolvedIdentityTests_ShouldResolveAnIdentityAndAddRowToResolvedIdentityTable()
        {
            var infra = new Infrastructure.Identities(Configuration.InitConfiguration()["ConnectionString"]);
            await infra.ResolveIdentity(erroneousDeviceId: new Guid("85E33FB5-C321-4EF2-994C-C835F136BA0C"), actualDeviceId: new Guid("CE810507-C614-4C65-9675-569EEFFDBC9F"));

            // now call GetResolvedIdentity so we can verify it was resolved.
            var resolvedIdentity = await infra.GetResolvedIdentity(new Guid("85E33FB5-C321-4EF2-994C-C835F136BA0C"));
            Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity.ActualDeviceId, expected: new Guid("CE810507-C614-4C65-9675-569EEFFDBC9F"));
            Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity.SiteName, expected: "rito.site");
            Assert.IsFalse(resolvedIdentity.ResolvedIdentity.Id == -1);
            Assert.AreEqual(actual: resolvedIdentity.ResolutionStatus, expected: IdentityResolutionState.Resolved);
        }

        [TestMethod]
        public async Task GetResolvedIdenity_ShouldResolveToBlacklisted()
        {
            var infra = new Infrastructure.Identities(Configuration.InitConfiguration()["ConnectionString"]);
            var resolvedIdentity = await infra.GetResolvedIdentity(new Guid("94FF1C23-0B7E-41CB-A0F8-058CED0465B3"));

            Assert.AreEqual(actual: resolvedIdentity.ResolutionStatus, expected: IdentityResolutionState.Blacklisted);
            Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity, expected: null);
        }

        [TestMethod]
        public async Task GetResolvedIdenity_ShouldResolveToStillPending()
        {
            var infra = new Infrastructure.Identities(Configuration.InitConfiguration()["ConnectionString"]);
            var resolvedIdentity = await infra.GetResolvedIdentity(new Guid("D3F32F97-2375-47CC-86E7-37C50ABAC85F"));

            Assert.AreEqual(actual: resolvedIdentity.ResolutionStatus, expected: IdentityResolutionState.Pending);
            Assert.AreEqual(actual: resolvedIdentity.ResolvedIdentity, expected: null);
        }
    }
}

我不知道为什么这些测试中的任何一个仍处于待处理状态,或者这些警告是否是我应该关心的事情.

I have no idea why any of these tests will still be pending, or if the warnings are even something I should care about.

这是在 Resharper 测试运行器中,在 MS 测试运行器中运行时不显示警告(但也许它不显示警告?)

This is in the Resharper test runner, no warnings are shown when running in MS test runner (but maybe it doesn't display warnings?)

推荐答案

看起来像是 ReSharper 中的一个错误:

It looks like a bug in ReSharper:

https://resharper-support.jetbrains.com/hc/en-us/community/posts/360000057490-Unit-Test-Sessions-reports-Inconclusive-Test-not-run-

https://youtrack.jetbrains.com/issue/RSRP-469301

这篇关于完成后单元测试中的元素未决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆