I understand that nUnit failed Assert statements throw an exception, and that's how Test runners detect an error has occurred. My problem is that there is a general try-catch block in the production code that eats these Assert exceptions, and the Unity Test runner thinks the code is running without any issue. I've simplified the code to this:
[UnityTest]
public IEnumerator End2EndTests_Test_Foo()
{
try
{
Assert.Fail("Something is wrong.");
}
catch (Exception)
{
UnityEngine.Debug.Log("* Something went wrong. I ate this exception! yum yum *");
}
yield break;
}
As I mentioned, this test passes in Unity Test Runner. What's the remedy?
Note 1: I have not put any assertion inside the production code. The assertions are in callbacks that are invoked by the production code. If any exception happens in the callbacks, the production code catches them. That's how the failed assertion exceptions are caught by production code, not the Test runner.
Note 2: Some background: The production code sends a request to a server. When it receives a response, it invokes all subscribers (=callbacks). My test code has subscribed to the OnResponse event. The failed assertion is inside that callback. The general try-catch is inside the production code, embracing the invocation of the OnResponse event.
Note 3: I don't want to put a special catch statement for nUnit in the production code and re-throw the exception. That's a bad solution because the production code should not have any dependency on a testing framework.
It's OK for your test to subscribe to the callbacks, but you can't assert in the method that the callback invokes. All you can do is record information.
The test itself, after installing the callback should wait for it to be callback to complete and then assert on the saved information.