简体   繁体   English

C#单元测试布尔

[英]C# unit test boolean

I need help on writing a unit test for this 我需要为此编写单元测试的帮助

Public static Boolean InList(byte value, Type t)
{
    if (!Enum.IsDefined(t, value))
    {
       return false;
    }

    return true;
} 

This is what i written so far but it keep given me error "out of bound" 这是我到目前为止所写的内容,但它不断给我“超出范围”的错误

  [TestMethod()]
  Public void InListTest()
  {
     Assert.IsTrue(ValidationUI.InList(1, Type.EmptyTypes[0]));
  }

I don't expect what I wrote on unit test is what the test is asking for, i need some guidance. 我不希望我在单元测试中写的内容是测试所要求的,我需要一些指导。 Thanks in advance 提前致谢

This will test your method: 这将测试您的方法:

public enum TestEnum : byte {
  One = 1,
  Two = 2
}

[TestMethod()]
Public void InListTest()
{
    Assert.IsTrue(ValidationUI.InList(1, typeof(TestEnum));
    Assert.IsFalse(ValidationUI.InList(100, typeof(TestEnum));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM