简体   繁体   English

我如何解决 Assert.Is.True(顺便说一句,它不是错误的)在我的测试驱动开发中失败

[英]how do I solve Assert.Is.True (it's not meant to be False btw) failed in my Test Driven Development

I am setting up a data layer using Test Driven Development and at the moment I am on the 'FindMethodOK' but It will not pass due to Assert.Is.True failing.我正在使用测试驱动开发设置数据层,目前我正在使用“FindMethodOK”,但由于 Assert.Is.True 失败,它不会通过。 Any Help will be appreciated.任何帮助将不胜感激。

//create an instance of the class we want to create
clsPhoneCustomer APhoneCustomer = new clsPhoneCustomer();

//boolean variable to store the result of the validation 
Boolean Found = false;

//create some test data to use with the method 
int CustomerID = 1;

//invoke the method 
Found = APhoneCustomer.Find(CustomerID);

//test to see that the result is correct 
Assert.IsTrue(Found);

Red test is good.红色测试很好。

Now to make it green you need to add minimal implementation - one option is just always return true:现在要使其成为绿色,您需要添加最少的实现 - 一种选择是始终返回 true:

class clsPhoneCustomer
{
    public bool Find(int id) { return true;}
}

Now test is green, you can add more tests that confirm that ID is actually used.现在测试是绿色的,您可以添加更多测试来确认实际使用了 ID。

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

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