私はNUnitテストランナーでspecflowを使用しています。テスト中のアプリケーションへの参照を取得するにはどうすればよいですか?
using System;
using TechTalk.SpecFlow;
using Xamarin.UITest.Android;
namespace UITest1
{
[Binding]
public class CategoryPagerSteps
{
[Given(@"The (.*)st category is selected")]
public void GivenTheStCategoryIsSelected(int p0)
{
ScenarioContext.Current.Pending();
}
[When(@"I swipe left")]
public void WhenISwipeLeft()
{
ScenarioContext.Current.Pending();
}
[Then(@"The (.*)nd category is selected")]
public void ThenTheNdCategoryIsSelected(int p0)
{
ScenarioContext.Current.Pending();
}
}
}
これは結構です、と私はこれらのシナリオを持つとき、私のキュウリのファイルと呼ばれる「ステップ」であることを理解:私は私の機能ファイルを書いて、ステップを生成するspecflowを頼むときは、次のコードを出力しガーキンに書かれているのは彼らのためです。
しかし、これは完全に統合されたUIテストであるため、Xamarin.UITest.Androidを使用してビューなどをクリックする必要があります。
だから私は何とかテスト中のアプリケーションを表すオブジェクトをつかむ必要があるので、UI操作を実行できます。私はプロパティAndroidApp app
は私が必要なオブジェクトであることがわかります
using NUnit.Framework;
using Xamarin.UITest;
using Xamarin.UITest.Android;
namespace UITest1
{
[TestFixture]
public class Tests
{
AndroidApp app;
[SetUp]
public void BeforeEachTest()
{
// TODO: If the Android app being tested is included in the solution then open
// the Unit Tests window, right click Test Apps, select Add App Project
// and select the app projects that should be tested.
app = ConfigureApp
.Android
// TODO: Update this path to point to your Android app and uncomment the
// code if the app is not included in the solution.
//.ApkFile ("../../../Android/bin/Debug/UITestsAndroid.apk")
.StartApp();
}
[Test]
public void AppLaunches()
{
app.Screenshot("First screen.");
}
}
}
:
今、私は、このオブジェクトが「Tests.cs」と呼ばれる別の自動生成テスト・フィクスチャファイルで初期化されていることがわかりますアクセスできますが、上記のCategoryPagerSteps
コードからそのプロパティにアクセスするにはどうすればよいですか? Tests
は静的でも、メソッドやプロパティでもありません。おそらくテストランナーによって行われるはずなので、私はそれを簡単にインスタンス化するのが気になりますよね?他の自動生成ファイルの1つにはtestRunnerプロパティが含まれていますが、privateとマークされています。
私が行ったすべてのアベニューはブロックされたように見え、私は何かが明らかでないと感じています。ここで
を見てみましょう:この記事は深さで説明しhttp://arteksoftware.com/bdd-tests-with-xamarin-uitest-and-specflow/ SpecFlow + Xamarin.UITestで始める方法 – Cheesebaron