C# 使用MiniProfiler和Dapper不会提供任何分析数据
我正在进行一个与dapper一起工作的单元测试。 我读过以下文章: 下面是我写的代码:C# 使用MiniProfiler和Dapper不会提供任何分析数据,c#,unit-testing,dapper,miniprofiler,C#,Unit Testing,Dapper,Miniprofiler,我正在进行一个与dapper一起工作的单元测试。 我读过以下文章: 下面是我写的代码: [TestMethod] public void GetEmployeesTest() { var profiler=MiniProfiler.Start("Dapper Test"); using (profiler.Step("Test")) { using (DbConnection cnn = new
[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());
}
[TestMethod]
public void GetEmployeesTest()
{
var profiler=MiniProfiler.Start(“短小测试”);
使用(分析器步骤(“测试”))
{
使用(DbConnection cnn=newsqlconnection(“服务器=;初始目录=北风;集成安全性=true;”)
{
var pcnn=new StackExchange.profileing.Data.ProfiledDbConnection(cnn,profiler);
pcnn.Open();
var employees=pcnn.Query(“从员工中选择*);
var count=pcnn.ExecuteScalar(“从员工中选择计数(*));
Assert.AreEqual(count,employees.count());
}
}
Console.WriteLine(profiler.RenderPlainText());
}
问题是控制台上没有打印数据
更新:
问题不在Console.WriteLine
(我还使用了Debug.WriteLine
和TestContext.WriteLine
)。
真正的问题是为什么profiler.RenderPlainText()
返回空字符串
有什么我遗漏的吗?这是一个单元测试,您应该使用Assert方法来找出正确或错误的地方。不需要在控制台上打印某些内容。
对于单元测试或模拟数据库,最好在内存中使用sql。因为其他测试可能会操纵数据并导致此测试失败。现在查看更新。将投票重新打开帖子,因为重复内容不再适用。