10

我知道如何用 Nunit 写这个,

Assert.That(exception, Is.InstanceOfType(typeof(TypeNotRegisteredException)));

我如何在 Xunit 中编写相同的东西,因为 Xunit 没有Assert.That.

4

2 回答 2

11

您可能正在寻找:

Assert.IsType<TypeNotRegisteredException>(exception);

让我知道这是否接近您正在寻找的内容。

于 2013-06-04T05:34:56.230 回答
4

我在想你在问什么是InstanceOfTypeassert 的等价物而不是Assert.That. 后者只是一种更好的语法,使您能够像英语一样阅读断言。

InstanceOfTypeXunit中 assert 的等价物是IsType

Assert.IsType<TypeNotRegisteredException>(exception);

请注意,nunit 等价物确实是:

Assert.IsInstanceOf<TypeNotRegisteredException>(exception);

(旧的IsInstanceOfType断言已被弃用 - http://www.nunit.org/index.php?p=typeAsserts&r=2.5.1

于 2013-06-04T05:30:38.347 回答