单元测试中的元素在完成后仍待处理

问题描述 投票:0回答:5

运行测试后,我在 Resharper 中看到此警告,所有测试都通过了。

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 已离开 运行完成后待处理。

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

这是完整的测试课程:

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);
        }
    }
}

我不知道为什么这些测试仍然悬而未决,或者这些警告是否是我应该关心的事情。

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

c# unit-testing resharper
5个回答

5
投票

将我的解决方案平台从任何 CPU 更改为 x64 为我解决了这个问题。


4
投票

由于这是第一个答案,当我在网上搜索并且上述答案没有解决时,这是我的解决方案:

更新 Resharper 为我解决了这个问题。

即使我启用了自动更新,防火墙仍然阻止我更新。解决方法很简单,从 https://www.jetbrains.com/resharper/download/#section=offline-installer 下载离线安装程序,然后手动更新版本。

版本 > 2020.2 应该不会有这些问题。


0
投票

ReSharper 测试运行程序中的测试显示为“不确定”且没有任何解释,这是 ReSharper 中常见的、反复出现的问题。

它可能有多种原因,因此没有单一的正确答案。

接受的答案中链接的错误只是导致此问题的一种特定情况,但根本问题仍然存在,可能是由于 ReSharper 中的错误处理不当造成的。更令人沮丧的是,当某些测试或子类别没有结论时,父类别和整个测试会话仍然会显示为成功。

在某些情况下,可以通过重建、更改配置或清除 ReSharper 缓存来解决问题。如果这没有帮助,则测试代码或其构建存在可重复的错误。


0
投票

这可能是由于版本控制中切换分支引起的。显示为“不确定”的测试可能根本不存在于您切换到的分支中,但它们仍然由 ReSharper 缓存。

清除 ReSharper 缓存应该可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.