I'm planning an Apigility driven RESTful Zend Framework 2 application. For unit testing and probably also for database testing PHPUnit will be used. Now I'm about to defining functional tesgin for the application.
"Functional testing" means for me the testing of the real functionality. It also gets an integration testing aspect, since the application gets then tested "intermodularily", so it's a testing across the units/modules. (Is my understanding of the functional testing correct?)
For this testing real request will be sent and the responces compared with the expectations. With the writing requests it might be a bit more complex, but to keep it simple let's consider the GET
case only first.
(Right?)
For this purpose using of behavior testing seems to make sence. (Actually I simply don't see any other appropriate approaches.) (Right?)
If one of my logical steps is false, please correct me.
What behavior testing tools can be used in the context of a RESTful PHP (ZF2) application? PHPUnit Story Extension? behat? phpspec? Other frameworks? Or maybe direct testing over PHPUnit (defining a separate test suite and executing in its test classes behavior tests with API-calls)?
Or is all this wrong and the functional testing needs a completely different approach?
Behat is a perfectly acceptable tool for behavior tests against an Apigility application (or any application).
If you're speaking of APIs specifically (which Apigility generally is), you can also look at Dredd from apiary.io. It's a great tool for testing after you document your API (plenty of other benefits of doing that as well)
All of your examples of tools (PHPUnit Story Extension, behat, phpspec) are tied to PHP... In fact, you can broaden your search.
The nice thing with black box testing of a Web application is that you don't need to use a framework tied with the language you used "inside the box".
For example, I use Capybara to test my Web applications, while none of them are done with Ruby. Choose the one that best fits your style of testing.
I've chosen Capybara for its user-centered approach and readability:
require 'spec_helper'
feature 'Register' do
scenario 'as a new user' do
visit '/register.html'
fill_in 'Username', :with => a_string()
fill_in 'Password', :with => 'secret'
fill_in 'Confirm password', :with => 'secret'
click_on 'submit'
expect(page).to have_content "Your account has been created"
end
scenario 'not as an existing user' do
visit '/register.html'
fill_in 'Username', :with => 'hatter'
fill_in 'Password', :with => 'secret'
fill_in 'Confirm password', :with => 'secret'
click_on 'submit'
expect(page).to have_content 'username already exists'
end
end
And if your application is more like an API, you can find other kind of languages that are better suited for this (like Frisby.js):
test.create('Site cookie authentication')
.post('http://cassandre.local:1337/_session', {name:'alice', password:'whiterabbit'})
.expectStatus(200)
.after(function(error, resource) {
test.create('HTTP cookie authentication use')
.get('http://cassandre.local:1337/text/Wonderland/')
.addHeader('Cookie', resource.headers['set-cookie'])
.expectStatus(200)
.toss();
})
.toss();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With