我需要测试以下代码吗?
public double LoadPercent
{
get { return _loadPercent; }
private set
{
RaisePropertyChanging("LoadPercent");
_loadPercent = value;
RaisePropertyChanged("LoadPercent");
}
}
我正在使用xUnit框架,如果set
不 private
,我会像这样编写测试:
[Fact]
public void LoadPercentTest()
{
// Arrange
var loader = new Loader();
bool notify = false;
// Act
loader.PropertyChanged += (sender, args) =>
{
if (args.PropertyName == "LoadPercent")
{
notify = true;
}
};
loader.LoadPercent = 20;
// Assert
Assert.True(notify, "Notification Failed");
}
我是单元测试的新手(初学者水平),我们将不胜感激。