visual-studio - 如何在 Visual Studio 中仅测量单元测试的 ACT 部分?
问题描述
众所周知,单元测试由三个 A 组成:A rrange、A ct、A ssert。问题是 Visual Studio 测量所有三个 A 的单元测试经过的时间。
我确信它应该只测量动作时间。
那么是否可以只测量动作时间?
解决方案
可能如果您在测试中使用Stopwatch 类自己测量它。
[TestMethod]
public void Some_Test() {
//Arrange
//...
Stopwatch stopWatch = new Stopwatch();
//Act
stopWatch.Start();
//...
stopWatch.Stop();
//Assert
// Get the elapsed time as a TimeSpan value.
TimeSpan ts = stopWatch.Elapsed;
//...
}
问题是实际的测试适配器无法知道您在测试中的行为是什么,因此让视觉工作室能够实际测量它几乎是不可能的。
推荐阅读
- java - 如何创建具有相同权重和相同源顶点的多条边?
- xamarin.forms - 双击加载 UI - 仅限 iOS
- entity-framework - 将 Linq.Contains 方法添加到表达式函数
- r - 如何在 R 中为一组变量运行频率表,就像您在 SPSS 中说的 FREQUENCIES var1 TO var10 一样?
- python - 使用PyMuPDF逐页逐行从pdf中提取文本
- python - 使用 isinstance 对 float 和 int 键值进行字典理解
- groovy - groovy 错误地将“off”推断为布尔值而不是字符串
- php - processForm.php 给了我会话 ID 的零值
- c# - 从 db C# 中选择一些 id
- php - 添加包含类别的列表以供选择并将其保存为帖子的类别