Calabash和Specta进行 IOS的bdd测试环境的安装

作者: shaneZhang 分类: ios技术 发布时间: 2015-09-23 11:02

新建项目

  • 新建一个空白的单页面应用,命名为Quiz
  • 添加pod,pod init后在单元测试的target里面加如以下两个框架

    target :QuizTests do
      pod 'Specta'
      pod 'Expecta'
    end
  • pod install

添加Calabash

  • 添加基本依赖

    sudo gem install calabash
    sudo gem install calabash-cucumber
    cd /path/to_your_project
    calabash-ios gen

完成上述步骤后会在工程的目录下生成一个features的文件夹

  • 配置xcode

在主的target下复制出一个名为Quiz-cal的target
Screen-Shot-2015-05-06-at-10.54.01-1024x578

Screen-Shot-2015-05-06-at-10.57.23

执行shell


calabash-ios download

将上一步下载到的framework拖到工程中去

2015-09-23-33

在Quiz-cal target的编译参数中Other Linker Flags下配置以下参数


-force_load “$(SRCROOT)/calabash.framework/calabash” -lstdc++

开始运行

  • 用模拟器运行 Quiz-cal的target后会产生类似如下的输出

2015-05-06 12:49:00.797 Quiz copy[3562:204375] Creating the server: 
2015-05-06 12:49:00.799 Quiz copy[3562:204375] Calabash iOS server version: CALABASH VERSION: 0.14.1
2015-05-06 12:49:00.799 Quiz copy[3562:204375] App Base SDK: iphonesimulator8.1
2015-05-06 12:49:00.799 Quiz copy[3562:204375] simroot: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
2015-05-06 12:49:00.817 Quiz copy[3562:204375] Started LPHTTP server on port 37265
2015-05-06 12:49:01.137 Quiz copy[3562:204375] WKWebView is not available
2015-05-06 12:49:01.702 Quiz copy[3562:204890] Bonjour Service Published: domain(local.) type(_http._tcp.) name(Calabash Server)
  • 以上环境表示你的基础环境基本搭建完毕了

开始测试运行环境

  • 在工程的features下删除my_first.feature,新建一个take_a_quiz.feature并且复制进如下代码

Feature: Take a quiz
As a user
I want to take a quiz
So I can improve my general knowledge

Scenario: View quiz question
Given I am on the Quiz Screen
When I view a question
Then a question is displayed
And the answer is not displayed

Scenario: View next question
Given I am on the Quiz Screen
And I am viewing a question
When I view the next question
Then a new question is displayed
And the answer is not displayed

Scenario: View answer
Given I am on the Quiz Screen
And I am viewing a question
When I give up and view the answer
Then the answer is displayed

Scenario: View next question after viewing an answer
Given I am on the Quiz Screen
And I am viewing a question with answer displayed
When I view the next question
Then a new question is displayed
And the answer is not displayed
  • 编辑 support/env.rb,添加如下设置

require 'calabash-cucumber/cucumber'
require 'rspec/expectations'
  • 运行shell 会有如下的类似输出,表明环境基本搭建ok

$ cucumber

Feature: Take a quiz
  As a user
  I want to take a quiz
  So I can improve my general knowledge

  Scenario: View quiz question      # features/take_a_quiz.feature:6
    Given I am on the Quiz Screen   # features/take_a_quiz.feature:7
    When I view a question          # features/take_a_quiz.feature:8
    Then a question is displayed    # features/take_a_quiz.feature:9
    And the answer is not displayed # features/take_a_quiz.feature:10

  Scenario: View next question       # features/take_a_quiz.feature:12
    Given I am on the Quiz Screen    # features/take_a_quiz.feature:13
    And I am viewing a question      # features/take_a_quiz.feature:14
    When I view the next question    # features/take_a_quiz.feature:15
    Then a new question is displayed # features/take_a_quiz.feature:16
    And the answer is not displayed  # features/take_a_quiz.feature:17

  Scenario: View answer                # features/take_a_quiz.feature:19
    Given I am on the Quiz Screen      # features/take_a_quiz.feature:20
    And I am viewing a question        # features/take_a_quiz.feature:21
    When I give up and view the answer # features/take_a_quiz.feature:22
    Then the answer is displayed       # features/take_a_quiz.feature:23

  Scenario: View next question after viewing an answer # features/take_a_quiz.feature:25
    Given I am on the Quiz Screen                      # features/take_a_quiz.feature:26
    And I am viewing a question with answer displayed  # features/take_a_quiz.feature:27
    When I view the next question                      # features/take_a_quiz.feature:28
    Then a new question is displayed                   # features/take_a_quiz.feature:29
    And the answer is not displayed                    # features/take_a_quiz.feature:30

4 scenarios (4 undefined)
18 steps (18 undefined)
0m45.916s

You can implement step definitions for undefined steps with these snippets:

Given(/^I am on the Quiz Screen$/) do
  pending # express the regexp above with the code you wish you had
end

When(/^I view a question$/) do
  pending # express the regexp above with the code you wish you had
end

Then(/^a question is displayed$/) do
  pending # express the regexp above with the code you wish you had
end

Then(/^the answer is not displayed$/) do
  pending # express the regexp above with the code you wish you had
end

Given(/^I am viewing a question$/) do
  pending # express the regexp above with the code you wish you had
end

When(/^I view the next question$/) do
  pending # express the regexp above with the code you wish you had
end

Then(/^a new question is displayed$/) do
  pending # express the regexp above with the code you wish you had
end

When(/^I give up and view the answer$/) do
  pending # express the regexp above with the code you wish you had
end

Then(/^the answer is displayed$/) do
  pending # express the regexp above with the code you wish you had
end

Given(/^I am viewing a question with answer displayed$/) do
  pending # express the regexp above with the code you wish you had
end

原文地址

本页面支持繁体中文友好显示:Calabash和Specta进行 IOS的bdd测试环境的安装

如果觉得我的文章对您有用,请随意打赏。如果有其他问题请联系博主QQ(909491009)或者下方留言!

发表回复