Pex は、特性評価テストの観点からは興味深いように見えますが、参照によって渡されたオブジェクトの変更をアサートするのに苦労しています。
以下でテストしようとしているコードを考えると:
public class ItemUpdater
{
public void Update(Item item)
{
if (item.Name == "Two Times")
{
item.Quantity = item.Quantity*2;
}
if (item.Name == "Two more") {
item.Quantity = item.Quantity + 2;
}
}
}
public class Item
{
public string Name { get; set; }
public int Quantity { get; set; }
}
私がやろうとしているのは、変更を加えることができるように、Characterisation/Locking テストを生成する Update に対して Intellitest テストを作成して実行することです。
テストが生成されると、次のようになります。
[TestClass]
[PexClass(typeof(ItemUpdater))]
[PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
[PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
public partial class ItemUpdaterTest
{
/// <summary>Test stub for Update(Item)</summary>
[PexMethod]
public void UpdateTest([PexAssumeUnderTest]ItemUpdater target, Item item) {
PexAssume.IsNotNull(item);
target.Update(item);
var quality = item.Quantity;
PexAssert.AreEqual(quality, item.Quantity);
// TODO: add assertions to method ItemUpdaterTest.UpdateTest(ItemUpdater, Item)
}
}
null チェック テストを削除するための想定を追加しましたが、ここでは問題ありません。
私が抱えている問題は、item.Quantity アサーションを自動生成するために最も知的なものになることです。また、品質をパラメータとして UpdateTest(...., int quality) に渡そうとしましたが、これは常にゼロに設定されています。
出てくるのは次のとおりです。
[TestMethod]
[PexGeneratedBy(typeof(ItemUpdaterTest))]
public void UpdateTest515()
{
ItemUpdater s0 = new ItemUpdater();
Item s1 = new Item();
s1.Name = "Two more";
s1.Quantity = 0;
this.UpdateTest(s0, s1);
Assert.IsNotNull((object)s0);
}
item.Quantity の値に対するアサーションはありません。
Update メソッドが呼び出された後に、返された item.Quality に対して Pex/Intellitet にアサーションを生成させる方法を知っている人はいますか?