为什么 Assets 在 Unit Android Test Runner 中等于 0(零)?
Why Asserts equals 0 (zero) in NUnit Android Test Runner?
如标题所述,为什么在我的NUnit Android Test Runner中显示Asserts: 0
,尽管在相应的测试方法中调用了两个Assert
?只是好奇我是否以错误的方式进行断言,或者显示的信息可能与我认为的完全不同。
测试方法如下。两条 Assert
行上的断点按预期命中。
[Test]
public async Task TestDeleteHistoryShouldEmptyTable()
{
var newBookmark = new Bookmark
{
Id = "foo",
Page = 100,
CreatedBy = "john doe",
CreatedDate = DateTime.Now
};
await _mainVM.Repo.SaveAsync(newBookmark);
var historyBefore = await _mainVM.Repo.GetLatestBookmarksAsync(Helpers.HistorySize);
Assert.True(historyBefore.Any());
await _mainVM.Repo.ClearTable("Bookmark");
var historyAfter = await _mainVM.Repo.GetLatestBookmarksAsync(Helpers.HistorySize);
Assert.True(!historyAfter.Any());
}
更新:
问题也可以使用以下测试方法重现:
[Test]
public async Task TestAsyncCounter()
{
await FakeAsyncMethod();
Assert.True(true);
}
public async Task FakeAsyncMethod()
{
await Task.Delay(1000);
}
@CharliePoole, one of the NUnit maintainer in their issue tracker确认这是一个框架错误:
"OK, I have to take back that last comment. It works correctly when the awaited method doesn't contain an await itself and is therefore processed synchronously. I'm seeing odd results when I include await Task.Delay(1)
in the awaited method. So there is definitely a framework bug and it can even be seen in .NET 4.5."
让我们暂时等待问题跟踪器中的更新。
已更新问题跟踪器 link:https://github.com/nunit/nunit/issues/1499
如标题所述,为什么在我的NUnit Android Test Runner中显示Asserts: 0
,尽管在相应的测试方法中调用了两个Assert
?只是好奇我是否以错误的方式进行断言,或者显示的信息可能与我认为的完全不同。
测试方法如下。两条 Assert
行上的断点按预期命中。
[Test]
public async Task TestDeleteHistoryShouldEmptyTable()
{
var newBookmark = new Bookmark
{
Id = "foo",
Page = 100,
CreatedBy = "john doe",
CreatedDate = DateTime.Now
};
await _mainVM.Repo.SaveAsync(newBookmark);
var historyBefore = await _mainVM.Repo.GetLatestBookmarksAsync(Helpers.HistorySize);
Assert.True(historyBefore.Any());
await _mainVM.Repo.ClearTable("Bookmark");
var historyAfter = await _mainVM.Repo.GetLatestBookmarksAsync(Helpers.HistorySize);
Assert.True(!historyAfter.Any());
}
更新:
问题也可以使用以下测试方法重现:
[Test]
public async Task TestAsyncCounter()
{
await FakeAsyncMethod();
Assert.True(true);
}
public async Task FakeAsyncMethod()
{
await Task.Delay(1000);
}
@CharliePoole, one of the NUnit maintainer in their issue tracker确认这是一个框架错误:
"OK, I have to take back that last comment. It works correctly when the awaited method doesn't contain an await itself and is therefore processed synchronously. I'm seeing odd results when I include
await Task.Delay(1)
in the awaited method. So there is definitely a framework bug and it can even be seen in .NET 4.5."
让我们暂时等待问题跟踪器中的更新。
已更新问题跟踪器 link:https://github.com/nunit/nunit/issues/1499