トップ回答者
UWP 単体テストでExpectedExceptionでエラーが出る。

質問
-
UWPの単体テストで、MSDNのチュートリアルを参考にしているのですが、ExpectedExceptionでエラーが発生します。
解決方法を探しているのですが、見つかっていないのでご存知の方がおられたらアドバイスいただけないでしょうか。
参考にしているサイトはこちら ⇒ https://msdn.microsoft.com/ja-jp/library/ms182532.asp
エラー内容
エラー CS0246 型または名前空間の名前 'ExpectedExceptionAttribute' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー CS0246 型または名前空間の名前 'ExpectedException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
using System; using Microsoft.VisualStudio.TestPlatform.UnitTestFramework; using BankAccountNS; namespace BankTests { [TestClass] public class BankAccountTests { [TestMethod] public void TestMethod1() { } [TestMethod] public void Debit_WithValidAmount_UpdatesBalance() { //arrange double beginningBalance = 11.99; double debitAmount = 4.55; double expected = 7.44; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); //act account.Debit(debitAmount); //accert double actual = account.Balance; Assert.AreEqual(expected, actual, 0.001, "Account not debited correctly"); } #if true //unit test method [TestMethod] [ExpectedException(typeof(ArgumentOutOfRangeException))] public void Debit_WhenAmountIsLessThanZero_ShouldThrowArgumentOutOfRange() { //arrange double beginningBalance = 11.99; double debitAmount = -100.00; BankAccount account = new BankAccount("Mr. Bryan Walton", beginningBalance); //act account.Debit(debitAmount); //assert is handled by ExpectedException } #endif } }
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー内容
エラー CS0246 型または名前空間の名前 'ExpectedExceptionAttribute' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー CS0246 型または名前空間の名前 'ExpectedException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー内容
エラー CS0246 型または名前空間の名前 'ExpectedExceptionAttribute' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー CS0246 型または名前空間の名前 'ExpectedException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー内容
エラー CS0246 型または名前空間の名前 'ExpectedExceptionAttribute' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
[ExpectedException(typeof(ArgumentOutOfRangeException))]
エラー CS0246 型または名前空間の名前 'ExpectedException' が見つかりませんでした (using ディレクティブまたはアセンブリ参照が指定されていることを確認してください)。
回答
すべての返信
-
こんにちは。
早速のご返答ありがとうございます。
早速試してみたのですが、下記のエラーが出てしましました。
usingの対応が抜けているのかな? と下記エラーについて調べています。
エラー CS0426 型名 'ThrowsException' が型 'Assert' に存在しません。 BankTests
エラー CS0426 型名 'ThrowsExceptionAttribute' が型 'Assert' に存在しません。 BankTests
変更前 [ExpectedException(typeof(ArgumentOutOfRangeException))]
変更後 [Assert.ThrowsException(typeof(ArgumentOutOfRangeException))]