ICloneable 的 C# 测试用例
C# test cases for ICloneable
如何在编写测试用例时覆盖 object ICloneable.Clone()
方法。
#region ICloneable Members
object ICloneable.Clone()
{
return this.Clone();
}
public new Blue Clone()
{
Blue _temp = (Blue)this.MemberwiseClone();
_temp.Node = Node.Clone();
return _temp;
}
#endregion
目前的覆盖面是这样的
.
虽然这些可以是不同的情况,但这里是 testing/covering 所示代码的真正简化示例。
//Arrange
Blue expected = new(); //populate as needed
//Act
Blue a = expected.Clone();
Blue b = (Blue)((ICloneable)expected).Clone();
//Assert - using FluentAsertions - cases should be self explanatory
a.Should().BeEquivalentTo(b);
a.Should().BeEquivalentTo(expected);
b.Should().BeEquivalentTo(expected);
如何在编写测试用例时覆盖 object ICloneable.Clone()
方法。
#region ICloneable Members
object ICloneable.Clone()
{
return this.Clone();
}
public new Blue Clone()
{
Blue _temp = (Blue)this.MemberwiseClone();
_temp.Node = Node.Clone();
return _temp;
}
#endregion
目前的覆盖面是这样的
虽然这些可以是不同的情况,但这里是 testing/covering 所示代码的真正简化示例。
//Arrange
Blue expected = new(); //populate as needed
//Act
Blue a = expected.Clone();
Blue b = (Blue)((ICloneable)expected).Clone();
//Assert - using FluentAsertions - cases should be self explanatory
a.Should().BeEquivalentTo(b);
a.Should().BeEquivalentTo(expected);
b.Should().BeEquivalentTo(expected);