Assert.AreEqual失败.应为:<;(Null)>;

本文关键字:Null gt AreEqual lt 应为 Assert 失败 | 更新日期: 2023-09-27 18:27:02

我正在进行编码Ui测试。当我运行我的测试时:

 public partial class UIMap
{
    public UIMap()
    {
        this.TestInit();
    } 
    private HandlingUnitDataController huDC = new HandlingUnitDataController();
    public DataTransferHandlingUnit testHU = new DataTransferHandlingUnit();        
    public void pressEnter3()
 {    
          List<DataTransferHandlingUnit> DataList;                      

        DataList = huDC.GetHandlingUnits(null);
        foreach (DataTransferHandlingUnit hu in DataList)
        {
            if (hu.idlabel == this.IdLabelInputParams.UIScannBoxEdit2Text)
            {
                testHU = hu;
                break;
            }
        }           
        Assert.AreEqual(testHU.idlabel,this.IdLabelInputParams.UIScannBoxEdit2Text);  
        }

发生错误:

Assert.AreEqual失败应为:<(空)>

我做错了什么?谢谢

Assert.AreEqual失败.应为:<;(Null)>;

我的猜测是

if (hu.idlabel == this.IdLabelInputParams.UIScannBoxEdit2Text)

不评估为真,因此您的

public DataTransferHandlingUnit testHU = new DataTransferHandlingUnit();  

仍在testHU引用中,并且testHU.idlabel为空