问题
Is it possible to use Cucumber outside Rails? I'd like to start using it for testing some of my PHP applications, but I really don't know how to start.
Probably the easiest way would be creating a Rails project only to run Cucumber features, but that seems like to me as overkill.
What is the simplest way to set up Cucumber for testing a non-Rails application?
回答1:
Check out:
https://github.com/cucumber/cucumber/wiki/php
It is easy to use cucumber with PHP, even managing the database.
回答2:
Checkout http://everzet.com/Behat/ (the URL appears to have changed to http://behat.org/)
回答3:
Cited from the cucumber website:
Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 30 spoken languages.
回答4:
Here's a great example of how to functionally test a PHP Webapp using Cucumber ... it will show you how to set up your test folder and where to put steps http://jystewart.net/2008/11/10/testing-php-apps-with-ruby-tools/
Check out what this guy has done with Capybara.
Capbyara is a package that lets you choose your CLI browser driver - basically you can preface tests with @javascript and the Scenario will be played out using Selenium's very powerful chrome ... this allows you to smoothly test javascript where required!!!
http://otaqui.com/blog/1072/testing-remote-php-websites-with-capybara-cucumber-mechanize-selenium-2-webdriver-and-saucelabs/
Further, I've been checking out this link, where the author uses Cuke4PHP to integrate PHPUnit with Cucumber ... this would then let you wrap PHPUnit tests in CucumberSteps ... allowing you to behaviorally test your application and DB using your existing PHP code http://lucato.it/php-bdd-cucumber-cuke4php
I myself am trying to meld all these pieces together into first a working and then robust test platform for a heavy-duty existing PHP webapp ... but I just began. Will update you if I make a good progress.
回答5:
You could definitely look at Behat and Mink. Behat is a runner for cucumber's Gherkin syntax (Given, When, Thens) and Mink lets Behat run real browsers. It provides you with a single API across several browser drivers, quite similar to Ruby's Capybara.
While using Cucumber and something like Webrat or Selenium to test a non Ruby application is ok, sticking with PHP if that's what your app is written has manifold benefits - developer skillset and ease of app setup (the kind of stuff you do in Given steps) being the most obvious.
回答6:
Behat, with Mink, PhantomJS and Sahi extensions, is a great BDD combo for php. If you are coming at it from a QA perspective, anyway.
来源:https://stackoverflow.com/questions/1389601/cucumber-for-php-application