我要测试的FillUpWater功能如下?
public bool FillUpWater()
{
WaterTap tap = new WaterTap();
if (tap.FillUpContainer())
{
Level = 5;
return true;
}
else
{
return false;
}
}
public void FillUpWater()
{
throw new NotImplementedException();
}
我的单元测试:
[TestClass()]
public class WaterContainer
{
[TestMethod()]
public void WhenWaterContainerIsEmpty_FillingItUp_CausesCorrectWaterLevel() // Uppgift 4: Vattenbehållaren fylls av
{ // vattenkranen automatisk om den är tom
// arrange
WaterContainer waterC = new WaterContainer(0);
WaterTap tap = new WaterTap();
// act
waterC= tap.FillUpContainer();
// assert
Assert.AreEqual(5, WaterC.Level);
//Assert.IsTrue(tap.FillUpContainer());
}
}
答案 0 :(得分:1)
我在这里可以看到一些问题。我已将每个问题都放在评论中......
[TestClass()]
public class WaterContainer
{
[TestMethod()]
public void WhenWaterContainerIsEmpty_FillingItUp_CausesCorrectWaterLevel() {
// There seems to be no relationship between the container
// and the tap - so how will the tap cause any change
// to the container?
WaterContainer waterC = new WaterContainer(0);
WaterTap tap = new WaterTap();
// The method that you shared with us is called:
// FillUpWater, but this is calling FillUpContainer
waterC= tap.FillUpContainer();
// You create a variable named:
// waterC, but use WaterC here (C# is case sensitive)
Assert.AreEqual(5, WaterC.Level);
}
}