2017-02-27 2 views
1

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를 물어 보면, 다음과 같은 코드를 출력 작은 오이 (Gherkin)에 적혀 있습니다.

그러나 이것은 완전히 통합 된 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은 정적도 아니며 메서드 또는 속성 중 하나입니다. 아마도 테스트 주자가 수행해야하기 때문에 간단하게 인스턴스화하는 것이 불안합니다. 맞습니까? 다른 자동 생성 파일 중 하나는 testRunner 특성을 포함하지만 private로 표시됩니다.

그래서 내가 간 모든 애비뉴가 막힌 것처럼 보입니다. 나는 분명히 뭔가 빠져 있다고 느낍니다.

arteksoftware에서 @CheeseBaron에서 제공하는 link 위로 다음, 트릭 값을 보유하는 SpecFlow의 FeatureContext.Current을 사용하는 것입니다

+1

에서보세요이 문서가 심도있게 설명 http://arteksoftware.com/bdd-tests-with-xamarin-uitest-and-specflow/ SpecFlow + Xamarin.UITest를 시작하는 방법 – Cheesebaron

답변

0

는 여기에 내가 유용하게 찾을 수있는 경우 다른 사람에, 그것을 해결 방법은 다음과 같습니다. 이것은 FeatureContext의 용도 중 하나입니다. [Setup]가 specflow 테스트의 일환으로 호출 할 수 없습니다 것 바인딩 때문에

[SetUp] 
public void BeforeEachTest() 
{ 
    app = AppInitializer.StartApp (platform, iOSSimulator); 
    FeatureContext.Current.Add ("App", app); 

    //This next line is not relevant to this post. 
    AppInitializer.InitializeScreens (platform); 
} 

그러나, 그것은 나를 위해 즉시 작동하지 않았다 :이 코드와 같이

arteksoftware에서 참조

은이 방법을 사용했다. 바인딩을 SpecFlow [BeforeFeature] 바인딩으로 변경하고 메서드를 정적으로 만들면 문제가 해결됩니다.

[BeforeFeature] 
public static void Before() 
{ 
    AndroidApp app; 

    Console.WriteLine("** [BeforeFeature]"); 
    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(<Path to APK>) 
     .StartApp(); 
    FeatureContext.Current.Add("App", app); 
} 

그런 기능 코드 자체에서 응용 프로그램은 지금처럼 FeatureContext 사전에서 추출 할 수있다 :

[Binding] 
public class FeatureSteps 
{ 
    AndroidApp app; 

    public FeatureSteps() 
    { 
     app = FeatureContext.Current.Get<AndroidApp>("App"); 
    } 

    //Code for the rest of your feature steps. 
} 

내가 하나의 테스트 러너의 선택은 바인딩 관련이 상상 사용되었으므로 여기에 "App.config"가 있습니다. SpecFlow 플러그인과 함께 NUnit을 사용하고 있습니다. 다른 테스트 러너 구성으로 시도하지 않았습니다.

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
    <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow" /> 
    </configSections> 
    <specFlow> 
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --> 
    <!-- For additional details on SpecFlow configuration options see http://go.specflow.org/doc-config --> 
    <!-- use unit test provider SpecRun+NUnit or SpecRun+MsTest for being able to execute the tests with SpecRun and another provider --> 
    <unitTestProvider name="NUnit" /> 
    <plugins> 
     <add name="SpecRun" /> 
    </plugins> 
    </specFlow> 
</configuration> 
관련 문제