【问题标题】:No profiling data is given using MiniProfiler and Dapper没有使用 MiniProfiler 和 Dapper 给出分析数据
【发布时间】:2020-01-10 09:00:12
【问题描述】:

我正在开发一个与 dapper 一起使用的单元测试。 我已阅读以下文章:

https://miniprofiler.com/dotnet/HowTo/ProfileSql

https://miniprofiler.com/dotnet/ConsoleDotNet

这是我写的代码:

    [TestMethod]
    public void GetEmployeesTest()
    {
        var profiler=MiniProfiler.Start("Dapper Test");
        using (profiler.Step("Test"))
        {
            using (DbConnection cnn = new SqlConnection("Server=.;Initial Catalog=Northwind;Integrated Security=true;"))
            {
                var pcnn = new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, profiler);
                pcnn.Open();
                var employees = pcnn.Query<Employee>("SELECT * FROM Employees");
                var count = pcnn.ExecuteScalar<long>("SELECT COUNT(*) FROM Employees");

                Assert.AreEqual(count, employees.Count());
            }
        }
        Console.WriteLine(profiler.RenderPlainText());

    }

问题是控制台上没有打印数据。

更新: 问题不在Console.WriteLine 中(我也使用了Debug.WriteLineTestContext.WriteLine)。 真正的问题是为什么profiler.RenderPlainText() 返回一个空字符串。

我有什么遗漏的吗?

【问题讨论】:

  • 现在看到更新。由于重复不再适用,将投票重新打开帖子。

标签: c# unit-testing dapper miniprofiler


【解决方案1】:

这是一个单元测试,你应该使用 Assert 方法来找出是对还是错。无需在控制台上打印任何内容。 而且最好在内存中使用 sql 进行单元测试或 Mock 数据库。因为其他测试可能会操纵数据并导致此测试失败。

【讨论】:

    猜你喜欢
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2018-06-02
    相关资源
    最近更新 更多