|
| 1 | +# TestGuy Standalone |
| 2 | +## Functional Testing Framework |
| 3 | + |
| 4 | +TestGuy is a functional testing framework powered by PHPUnit. |
| 5 | +Designed make tests easy to write, read, and debug. |
| 6 | + |
| 7 | +## Principles |
| 8 | +TestGuy library allows to write test scenarios in PHP with DSL designed to look like native English. |
| 9 | +Imagine your tester describes her actions and you write them as a functional tests! |
| 10 | +Tester can perform some actions and see the results. Whenever she doesn't see expected value the test fails. |
| 11 | +This is how testers act. And this is the same how TestGuy is acting. |
| 12 | + |
| 13 | +TestGuy knows a little about internals of your application. When error occur it won't tell you which module triggered this error. |
| 14 | +Still it makes you confident that your app is still running correctly and users can perform the same scenarios the TestGuy does. |
| 15 | + |
| 16 | +Cover your application with functional tests and let them stay simple to read, simple to write, and simple to debug. |
| 17 | +Use TestGuy! |
| 18 | + |
| 19 | +## In a Glance |
| 20 | +This is the sample TestGuy test. User is accessing the site to create a new wiki page about the movie. |
| 21 | +He gets to 'new' page, submits form, and sees the page he just created. Also he performs additional checks, if the slug is generated and if the database record is saved. |
| 22 | + |
| 23 | +``` php |
| 24 | +<?php |
| 25 | + |
| 26 | +$I = new TestGuy($scenario); |
| 27 | +$I->wantTo('create wiki page'); |
| 28 | +$I->amOnPage('/'); |
| 29 | +$I->click('Pages'); |
| 30 | +$I->click('New'); |
| 31 | +$I->see('New Page'); |
| 32 | +$I->submitForm('#pageForm', array('page' => array( |
| 33 | + 'title' => 'Tree of Life Movie Review', |
| 34 | + 'body' => 'Next time don\'t let Hollywood create arthouse =) ' |
| 35 | +))); |
| 36 | +$I->see('page created'); // notice generated |
| 37 | +$I->see('Tree of Life Movie Review','h1'); // head of page of is our title |
| 38 | +$I->seeInCurrentAddress('pages/tree-of-life-mobie-review'); // slug is generated |
| 39 | +$I->seeInDatabase('pages', array('title' => 'Tree of Life Movie Review')); // data is stored in database |
| 40 | + |
| 41 | +``` |
| 42 | + |
| 43 | +## About |
| 44 | + |
| 45 | +TestGuy uses PHPUnit (http://http://www.phpunit.de/) as backend for testing framework. If you are familiar with PHPUnit you can your TestGuy installation with it's features. |
| 46 | +Also TestGuy uses Mink (http://mink.behat.org/) a powerful library that provides interface for browser emulators. |
| 47 | +TestGuy was developed as symfony1 plugin and now it's migrated to standalone version. You can test any project with it! |
| 48 | + |
| 49 | +## Install |
| 50 | + |
| 51 | +If you need stable standalone version download [https://github.com/downloads/DavertMik/TestGuy_Standalone/testguy.phar](phar package). |
| 52 | + |
| 53 | +Put it wherever you expect to store your test suites. |
| 54 | + |
| 55 | +Install TestGuy dependencies. |
| 56 | + |
| 57 | +``` |
| 58 | +php testguy.phar install |
| 59 | +``` |
| 60 | + |
| 61 | +Generate empty test suite |
| 62 | + |
| 63 | +```` |
| 64 | +php testguy.phar init |
| 65 | +```` |
| 66 | + |
| 67 | +That will create a 'tests' directory with a sample suite inside it. |
| 68 | +By default suite will be configured to test web sites with Mink. |
| 69 | +Configuration is stored in ```tests/testguy/suites.yml````. |
| 70 | + |
| 71 | + |
| 72 | +Build TestGuy class |
| 73 | + |
| 74 | +```` |
| 75 | +php testguy.phar build |
| 76 | +```` |
| 77 | + |
| 78 | +Then your suite is ready to run first test file. |
| 79 | + |
| 80 | +```` |
| 81 | +php testguy.phar run |
| 82 | +```` |
| 83 | + |
| 84 | +You will see the result: |
| 85 | + |
| 86 | +```` |
| 87 | +Starting app... |
| 88 | +TestGuy 0.7 running with modules: Cli, Filesystem. |
| 89 | +Powered by PHPUnit 3.5.5 by Sebastian Bergmann. |
| 90 | +
|
| 91 | +
|
| 92 | +# Trying to test some feature of my app (SampleSpec.php) - ok |
| 93 | +
|
| 94 | +Time: 0 seconds, Memory: 8.75Mb |
| 95 | +
|
| 96 | +OK (1 test, 0 assertions) |
| 97 | +```` |
| 98 | + |
| 99 | +## Writing tests |
| 100 | + |
| 101 | +Each test belongs to suite. You can have several suites for different parts of your application. |
| 102 | +By default the 'app' test suite is crated and stored into ````tests/testguy/app````. |
| 103 | +Inside of it you will see a first test file: ````SampleSpec.php```` |
| 104 | + |
| 105 | +TestGuy tests should be placed in suite directory and should be ended with 'Spec.php'. |
| 106 | + |
| 107 | +Tests should always start with this lines: |
| 108 | + |
| 109 | +``` php |
| 110 | +<?php |
| 111 | +$I = new TestGuy($scenario); |
| 112 | +$I->wantTo('actions you are going to perform'); |
| 113 | +``` |
| 114 | + |
| 115 | +$I - is a magical object. It stores all actions you can perform. Just type ```$I->``` in your IDE and you will see what actions you can execute. |
| 116 | +For instance, the Web module is connected and you can open browser on specific page and test the expected result. |
| 117 | + |
| 118 | +``` php |
| 119 | +<?php |
| 120 | +$I = new TestGuy($scenario); |
| 121 | +$I->wantTo('see if registration page is here'); |
| 122 | +$I->amOnPage('/register'); |
| 123 | +$I->see('Registration'); |
| 124 | +``` |
| 125 | + |
| 126 | +ALl methods of $I object are taken from TestGuy modules. There are not much of them, but you can write your own. |
| 127 | +The most powerful module is Web module, it allows you to test wep sites with headless browser. |
| 128 | +You can connect as many modules as you like and use all them together. |
| 129 | + |
| 130 | +The detailed information on modules and configurations you can see [https://github.com/DavertMik/TestGuy_Modules](here) |
| 131 | + |
| 132 | +## Testing Methods |
| 133 | +The method names in $I object are designed to be easy to understand their meaning. |
| 134 | +There are 3 types of methods: |
| 135 | + |
| 136 | +* Conditions: start with ```am```. They specify the starting conditions. For example: ```$I->amOnPage('/login');``` |
| 137 | +* Assertions: start with ```see``` or ```dontSee```. They define the expected result and makes a test fail if result is not see. |
| 138 | +* Actions: all other actions. They change current application state. For example: ```$I->click('Signin');``` moves user to sign in page. |
| 139 | + |
| 140 | +## Sample tests |
| 141 | +You can look at sample tests here, in /tests/ dir. |
| 142 | + |
| 143 | +### License |
| 144 | +MIT |
| 145 | + |
| 146 | +(c) Michael Bodnarchuk "Davert" |
| 147 | +2011 |
0 commit comments