Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First integration tests for provisioning api #18105

Merged
merged 9 commits into from
Sep 29, 2015

Conversation

DeepDiver1975
Copy link
Member

@PVince81 @Raydiation @schiesbn @blizzz @karlitschek

So - before touching the provisioning api to implement V2 - I wanted to have integration tests to be sure nothing will be broken.

TODO:

  • setup jenkins on this branch
  • integrate this into the regular ci mechanism (AFTER merge)
  • test all provisioning APIs
  • get coverage results

@DeepDiver1975 DeepDiver1975 added this to the 8.2-current milestone Aug 6, 2015
@karlitschek
Copy link
Contributor

nice 👍

@DeepDiver1975
Copy link
Member Author

@MorrisJobke please have a look since you did use behat already as well - THX

@DeepDiver1975
Copy link
Member Author

@cmonteroluque @rperezb just FYI - this is what I was talking about in the past regarding integration testing of the OCS API

*/
public function userExists($user) {
throw new \Behat\Behat\Exception\PendingException();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation looks off compared with above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mimimi ... 🙈

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LukasReschke
Copy link
Member

Besides me doing mimimimimi, this is cool 🚀

private $baseUrl = '';

/** @var ResponseInterface */
private $response = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention :hides:

@DeepDiver1975
Copy link
Member Author

@Raydiation are you by chance aware of a way to collect coverage data of php dev server?

@BernhardPosselt
Copy link
Contributor

@DeepDiver1975 what I've found: Behat/Behat#92

@BernhardPosselt
Copy link
Contributor

TL;DR: Not needed for integration tests. 100% code coverage is only usable for unit tests because it would take too long otherwise

@BernhardPosselt
Copy link
Contributor

IMHO: write a simple parser for our API docs and run them against ownCloud :)

@BernhardPosselt
Copy link
Contributor

As in provide an example API call and the result, run the example call against the API with test data and then compare it :)

That way you generate API docs that are tested and also help you integration test stuff :)

@oparoz
Copy link
Contributor

oparoz commented Aug 6, 2015

Or use Codeception which has an API tester

http://codeception.com/docs/10-WebServices

<?php
$I = new ApiTester($scenario);
$I->wantTo('create a user via API');
$I->amHttpAuthenticated('service_user', '123456');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('/users', ['name' => 'davert', 'email' => '[email protected]']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContains('{"result":"ok"}');
?>

@DeepDiver1975
Copy link
Member Author

@DeepDiver1975 what I've found: Behat/Behat#92

I'm not talking about coverage on the behat process - but on the php -S localhost:8080

@DeepDiver1975
Copy link
Member Author

Or use Codeception which has an API tester

Well - there are plenty of tools - we finally simply need to get started ...

@BernhardPosselt
Copy link
Contributor

@DeepDiver1975 does unit test coverage fail because of the test server?

@BernhardPosselt
Copy link
Contributor

@oparoz
Copy link
Contributor

oparoz commented Aug 6, 2015

Well - there are plenty of tools - we finally simply need to get started ...

I have found that there were not that many, but I agree, tools should not slow down any effort to improve tests.

What I've gathered so far for Codeception

+

  • Faster
  • More readable tests
  • Does Behavioural, functional and unit with one "language", not intermediary language needed
  • Works better when lots of tests are needed

-

  • New syntax to learn for die-hard PHPunit fans

@scrutinizer-notifier
Copy link

A new inspection was created.

@DeepDiver1975
Copy link
Member Author

Jenkins is green 🎉

https://ci.owncloud.org/job/ocs-api-integration-tests/11/

@DeepDiver1975
Copy link
Member Author

What I've gathered so far for Codeception

I was looking at codeception multiple times - I don't want to introduce another paradigm

@oparoz
Copy link
Contributor

oparoz commented Aug 7, 2015

I was looking at codeception multiple times - I don't want to introduce another paradigm

OK. Just know that, although I haven't tested with core tests yet, my PHPUnit tests in other projects run without any changes. You only need to familiarise yourself with the new syntax and setup if your intend on writing new kind of tests (behavioural, API).

@MorrisJobke
Copy link
Contributor

As in provide an example API call and the result, run the example call against the API with test data and then compare it :)

That way you generate API docs that are tested and also help you integration test stuff :)

@Raydiation I wrote exactly this some weeks back for another project ;) But it's not in the shape I want it

@DeepDiver1975
Copy link
Member Author

So @oparoz wrote one test with codeception - https://github.com/owncloud/gallery/blob/b84508a0b687b91b623c6f81ea99e5fe40daa846/tests/api/CreateUserCept.php

Looks interesting as well .... which path to choose?

@MorrisJobke @PVince81 @icewind1991 @blizzz

@oparoz
Copy link
Contributor

oparoz commented Aug 11, 2015

For the API stuff, Codeception is easy to use and coders can quickly get going. It's literally about typing a couple of commands and writing your first test, the same way you write a scenario. If you need to show the steps involved to a BA or a PO, then you can convert the script to English.

Example

$I->amHttpAuthenticated('admin', 'admin');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST($baseUrl . '/users', ['userid' => 'test', 'password' => 'test']);
$I->seeResponseCodeIs(200);
$I->seeResponseIsXml();
$I->seeXmlResponseIncludes(
    XmlUtils::toXml(
        ['status'   => 'ok']
));

becomes

* I am http authenticated "admin","admin"
* I have http header "Content-Type","application/x-www-form-urlencoded"
* I send post "/ocs/v1.php/cloud/users",{"userid":"test","password":"test"}
* I see response code is 200
* I see response is xml
* I see xml response includes "DOMDocument"

Of course, with Behat, once the commonly used steps are written in PHP, then things can go very fast as well from scenario to test and it might be more flexible.

Some potential problems

  • it will create a bunch of folders inside the folder you want to use, so, for core, you have to choose wisely. Maybe build/integration. The structure looks like this: https://github.com/owncloud/gallery/tree/testing-with-codeception/tests
  • if you want to use the codeception built-in server (add some config lines and you have a server running during the tests only), then you'll need to use composer to install all the dependencies and run codecept from vendor/bin. Otherwise, you can just use the phar to generate and run stuff. There may be a way around that. I haven't dug too deep.
  • if your QA engineers are used to working with Gherkin and have a backlog of acceptance tests, then you may not want to have 3 tests systems: PHPUnit for unit/integration, Behat for acceptance, Codeception for api/integration. In my projects, I prefer to use one tool for all three and it works because Codeception can execute PHPUnit tests.

I've written some more (more!?! ;)) on my decision to use it for Gallery here: owncloud/gallery#264 (comment)

@LukasReschke
Copy link
Member

FWIW I do prefer Gherkin (Behat) syntax.

@oparoz
Copy link
Contributor

oparoz commented Aug 11, 2015

It might be worth getting some feedback via the mailing list?

@oparoz
Copy link
Contributor

oparoz commented Aug 11, 2015

An older comparison of the two from 2 years ago. Things might have changed on both sides
http://codeception.com/05-06-2013/specification-testing-coparison.html

@MorrisJobke
Copy link
Contributor

I also like the gherkin syntax more.

@MorrisJobke
Copy link
Contributor

Tested and the code looks good. 👍

@DeepDiver1975 DeepDiver1975 force-pushed the ocs-api-integration-tests branch from 5efe5f4 to 2d1f509 Compare September 29, 2015 11:42
@DeepDiver1975
Copy link
Member Author

I'm merging this now @SergioBertolinSG any future test case via pull request please - THX

DeepDiver1975 added a commit that referenced this pull request Sep 29, 2015
First integration tests for provisioning api
@DeepDiver1975 DeepDiver1975 merged commit c061b3e into master Sep 29, 2015
@DeepDiver1975 DeepDiver1975 deleted the ocs-api-integration-tests branch September 29, 2015 12:23
@lock lock bot locked as resolved and limited conversation to collaborators Aug 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants