har07 har07 - 1 year ago 90
C# Question

Why Asserts equals 0 (zero) in NUnit Android Test Runner?

As mentioned in the title, why is it displayed

Asserts: 0
in my NUnit Android Test Runner, despite there are two
s being called in the corresponding test method? Just curious if I was doing assertion the wrong way, or maybe the information displayed means completely different from what I think it does.

enter image description here

The test method is as posted below. Breakpoints on the two
lines are hit as expected.

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

await _mainVM.Repo.ClearTable("Bookmark");
var historyAfter = await _mainVM.Repo.GetLatestBookmarksAsync(Helpers.HistorySize);


The problem can also be reproduced using the following test method :

public async Task TestAsyncCounter()
await FakeAsyncMethod();

public async Task FakeAsyncMethod()
await Task.Delay(1000);

Answer Source

This turned out to be a framework bug, as confirmed by @CharliePoole, one of the NUnit owner 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."

Let's just wait for updates in the issue tracker for now.

Updated issue tracker link : https://github.com/nunit/nunit/issues/1499

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download