2017-05-17 4 views
1

内部ITestResultインターフェイスを使用してNUnit 3でテスト結果を取得しようとしています。しかし、ITestResultオブジェクトを引き裂きメソッドに渡すと、「OneTimeSetup:SetUpまたはTearDownメソッドの無効なシグネチャ:TestFinished」というTestFinishedがティアダウンメソッドとしてリストされています。テストティアダウンでNUnit 3でITestResultを読む方法

私がオブジェクトを渡さないと、テストは正常に動作します。私は私の[TearDown]メソッドを私の基底クラスの代わりにテストを含む実際のクラスに移動しようとしましたが、同じエラーが発生します。私はTestFinish関数を各テストが完了するたびに実行させたいので、合格/不合格、あるいは私が今使っているアクション構造を使って試してみることではなく、例外メッセージの中にあるものに応じて行動することができます。ここ

下に自分のコードの構造である:

----開始し、試験を終了し、使用するwebdriverをオブジェクトを作成し、ファイル---

[OneTimeSetUp] 
    public void Setup() 
    { 
    //Do some webdriver setup... 
    } 

----ベーステストクラスそれは----セットアップに使用したり、テストのティアダウンされBaseTestClassを使用しています

[TestFixture] 
public class BaseTestClass 
{ 
    //Also use the webdriver object created at [OneTimeSetUp] 
    protected void TestRunner(Action action) 
    { 
     //perform the incoming tests. 
     try 
     { 
      action(); 
     } 

     //if the test errors out, log it to the file. 
     catch (Exception e) 
     { 
      //Do some logging... 
     } 
    } 

    [TearDown] 
    public void TestFinished(ITestResult i) 
    { 
     //Handle the result of a test using ITestResult object 
    } 
} 

----テストファイル----

class AccountConfirmation : BaseTestClass 
{ 

    [Test] 
    public void VerifyAccountData() { 

     TestRunner(() => { 
      //Do a test... 
     }); 

    } 
} 

答えて

1

TearDownメソッドからITestResultを削除し、代わりにTestContext.CurrentContext.Resultをメソッド内で使用してください。例えば

[Test] 
public void TestMethod() 
{ 
    Assert.Fail("This test failed"); 
} 

[TearDown] 
public void TearDown() 
{ 
    TestContext.WriteLine(TestContext.CurrentContext.Result.Message); 
} 

ウィル出力、

=> NUnitFixtureSetup.TestClass.TestMethod 
This test failed 
+0

これは感謝してTestContext.CurrentContext.Result.Outcomeを使用して正しい方向に私を指摘しました!これはできます:) –

関連する問題