NUnit 使用 TestCase 需要清晰

发布于 2024-10-08 17:00:49 字数 390 浏览 3 评论 0原文

我有一个这样的测试:

[TestCase(12, Result= typeof(mytype))]
public mytype GetById(int id)
{
yada, yada, yada.

}

in the NUnit error window, I see this:

Test.Tester.GetById(12):
  Expected: <mytype>
  But was:  <mytype>

我的问题是,这是预期的吗?有没有办法指定返回值的类型,当它是我自己的类型时,而不是整数、字符串等?我在网上找到的所有示例都只返回字符串或整数。我是否需要实际生成一个 mytype 实例并说它是我所期望的?

这是 NUnit 2.5.9。

I have a test like this:

[TestCase(12, Result= typeof(mytype))]
public mytype GetById(int id)
{
yada, yada, yada.

}

in the NUnit error window, I see this:

Test.Tester.GetById(12):
  Expected: <mytype>
  But was:  <mytype>

My question is, is this expected? Is there a way to specify the type of the returned value when its my own type, and not an integer, string, etc? All the examples I find on the web are only returning strings or ints. Do I need to actually generate a mytype instance and say that it is what I'm expecting?

This is NUnit 2.5.9.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

舂唻埖巳落 2024-10-15 17:00:49

Testcase Result=... 检查结果值而不是结果类型。

错误消息具有误导性,因为 type.ToString() 和 object.ToString() 会产生相同的消息

覆盖您的 myTpe.ToString() 方法,错误消息将成为

 Expected: <mytype>
 But was:  {your ToString() result goes here}

这些测试(nunit 2.5.7)按预期工作

    [TestCase(12, Result = "0")]
    public String GetById(int id)
    {
        return "0";
    }

    [TestCase(12, Result = typeof(mytype))]
    public System.Type GetByIdType(int id)
    {
        return typeof(mytype);
    }

Testcase Result=... checks the result value and not the result type.

The errormessage is misleading because type.ToString() and the object.ToString() result in the same messge

Override your myTpe.ToString() method and the errormessage will become

 Expected: <mytype>
 But was:  {your ToString() result goes here}

these tests (nunit 2.5.7) work as expected

    [TestCase(12, Result = "0")]
    public String GetById(int id)
    {
        return "0";
    }

    [TestCase(12, Result = typeof(mytype))]
    public System.Type GetByIdType(int id)
    {
        return typeof(mytype);
    }
╰沐子 2024-10-15 17:00:49

我以前从未见过这样传递结果。但是您不能将结果作为另一个参数传递吗?

[TestCase(12, 1)] 
public mytype GetById(int id, int result) 
{ 
   Assert.AreEqual(12, 1);
} 

它可能陈述了显而易见的事情,但预期:但是:
听起来很像将“true”与 true 进行比较时得到的结果。

I haven't seen the result being passed in like that before. But couldn't you just pass the result in as another parameter?

[TestCase(12, 1)] 
public mytype GetById(int id, int result) 
{ 
   Assert.AreEqual(12, 1);
} 

and it's probably stating the obvious, but Expected: But was:
sounds very like what you'd get when you compare "true" with true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文