Time to Read

2分

ざっくりしたものですが。。。

Ruby

Cucumber
http://cukes.info/
本家。「シナリオ(feature、など他の呼び方あり)」と「step definition」を分けて書くスタイル。
以下、step definition相当のサンプルをコピペしておく。シナリオ側は、Cucumberベースであればどの言語も似たようなものなので……。
1
2
3
4
5
6
7
8
9
Given /^I have a cardboard box$/ do
  transmogrifier = double('transmogrifier')
  transmogrifier.should_receive(:transmogrify)
  @box = CardboardBox.new(transmogrifier)
end
 
When /^I poke it all is good$/ do
  @box.poke
end
Capybara
https://github.com/jnicklas/capybara
RSpecやTest::Unitの書き方に乗っかる形で受け入れテストができる。ドライバーとしてRack::TestやSeleniumなどを選択可能。「ビヘイビア」と「step definition」を別々に用意する必要が無いので、カジュアルに導入できそう。

RSpecと一緒に使うサンプル

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
context 'as a guest on the sign in page' do
 
  #Make sure your factory generates a valid user for your authentication system
  let(:user) { Factory(:user) }
 
  #Browse to the homepage and click the Sign In link
  before do
    visit root_path
    click 'Sign In'
  end
 
  context 'with valid credentials' do
 
    #Fill in the form with the user’s credentials and submit it.
    before do
      fill_in 'Email', :with => user.email
      fill_in 'Password', :with => 'password'
      click 'Submit'
    end
 
    it 'has a sign out link' do
      page.should have_xpath('//a', :text => 'Sign Out')
    end
 
    it 'knows who I am' do
      page.should have_content("Welcome, #{user.email}!")
    end
 
  end
end

Groovy

そもそも、JVM言語にはcuke4dukeというものがあるようだ。色々あるけど、基本それをベースにしているのかな?

Grails-Cucumber
http://danlynn.com/grails-cucumber/
普通に移植版といった趣き……。GrailsがそもそもRubyと書いている感触が変わらないため、本家に慣れていればすんなり書けそう
1
2
3
4
Given(~/I have entered (\d+) into the calculator/) { int number ->
  calc = new calc.Calculator()
  calc.push number
}

Scala

Cucumber-sbt-plugin
https://github.com/skipoleschris/cucumber-sbt-plugin
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class CucumberSteps extends ScalaDsl with EN with ShouldMatchers {
 
  private var givenCalled = false
  private var whenCalled = false
 
  Given("""^A SBT project$""") {
    givenCalled = true
  }
 
  When("""^I run the cucumber goal$""") {
    whenCalled = true
  }
 
  Then("""^Cucumber is executed against my features and step definitions$""") {
    givenCalled should be (true)
    whenCalled should be (true)
  }
}

Python

Pyccuracy
http://pyccuracy.org/
ドキュメントを一通り眺めたけど、一通りのstep definitionsは最初から用意されているのだろうか?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class LoggedInAction(ActionBase):
    regex = r'^(And )?I am logged in with username [\"](?P<username>.+)[\"] and password [\"](?P<password>.+)[\"]$'
 
    def execute(self, context, username, password):
        self.execute_action(u"I go to \"/index.html\"", context)
 
        # if the user is not logged in already, we do the login process
        logged_in = False
        try:
            self.execute_action(u"And I see \"already have an account? sign in\" link", context)
        except ActionFailedError:
            logged_in = True
 
        if not logged_in:
            self.execute_action(u"And I click \"already have an account? sign in\" link", context)
            self.execute_action(u"And I wait for the page to load for 5 seconds", context)
            self.execute_action(u"And I fill \"username\" textbox with \"%s\"" % username, context)
            self.execute_action(u"And I fill \"password\" textbox with \"%s\"" % password, context)
            self.execute_action(u"And I click \"sign in\" button", context)

Perl

p5-cucumber
https://github.com/kesor/p5-cucumber
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Given qr/(.*) in (.*)/, sub {
  my ($description,$location) = @_;
  $state{human} = $description;
  $state{location} = $location;
};
 
When qr/s?he ate (.*)/, sub {
  my $item = shift;
  if ($item eq 'a mushroom') {
    $state{human} =~ s/live/dead/;
  }
};
 
Then qr/s?he was (.*) in (.*)/, sub {
  my ($description,$location) = @_;
  is($state{human},$description,$description);
  is($state{location},$location,$location);
};

PHPは、Rubyのcucumberを使うことになりそうです。というより、cucumber自体は言語を選ばない仕組みです(よね?)。

ザックリしか調べていないので、「~の言語では受け入れテストでは~を使うのが普通だよ!!!」とか情報募集です。