12

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?

automatix
  • 14,018
  • 26
  • 105
  • 230
  • 2
    I'm voting to close this question as off-topic because it seems more suited over at http://programmers.stackexchange.com/ – ʰᵈˑ May 22 '15 at 11:14
  • Thank you for your comment. I think, this question could actually be posted on programmers.stackexchange.com, but this place is correct as well. But anyway, even if not, I would not close, but just move it to programmers.stackexchange.com. – automatix May 22 '15 at 11:18
  • It's more suited over at programmers.SE because at this stage it's more conceptual rather than "I have this code, how would I fix this error". Feel free to c&p to programmers.SE and delete this one `:)` – ʰᵈˑ May 22 '15 at 11:19
  • This question is a resource request. It would be closed as off-topic at Programmers.SE. Please read: **[What goes on Programmers.SE? A guide for Stack Overflow](http://meta.programmers.stackexchange.com/q/7182/22815)**. –  May 22 '15 at 11:23
  • I also think it's wrong on programmers.SE, but I also think it should be moved to qsa.stackexchange.com – bish Jun 03 '15 at 07:38

2 Answers2

4

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)

Wilt
  • 41,477
  • 12
  • 152
  • 203
Tim Klever
  • 601
  • 5
  • 13
4

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();
Aurélien Bénel
  • 3,775
  • 24
  • 45
  • Thank you for your post. I cannot accept it and/or award the bounty, since I don't find there answers to my (theoretical) questions. But anyway, it provides very useful information I actually need, thanks for this! +1 – automatix Jun 07 '15 at 10:50