This document describes the plan for testing the inventory application. Originally these tests were done manually, however the tests are now done automatically with Selenium tests.
Automated tests take between 10-15 minutes to run. The automated testing should ideally be run before deploying a new release to the production inventory. The tests should be run against a dev copy of inventory, not a production copy.
You will notice browser windows opening and testing happening. Let this run. You should be able to lock your computer and come back in ~10 minutes and have the results of the tests. The IDE is fairly straightforward and easier to figure out when you're looking at it. These instructions may sound confusing, but the IDE is quite straightforward when you get going.
You'll then want to switch back to the test suites once you have finished making your test. If you want it in a new test suite, create a new one with the plus icon. If you want to add one to a suite you can hit the options button beside the suite name and click on "Add tests". Be sure to also add your new tests into the "All tests" suite as well so that there is also a place where you can run all of the tests at once.
I advise in your test adding a run Start, and run Finish to the beginning and end of your test. Check any of the tests to see what I am talking about. These call the "Start" and "Finish" test which handles creating a test inventory item, and then deleting it after. This ensures every test is using a fresh copy of the inventory item that has no issues with it.
Automated tests take about 6 minutes to run. I will instruct you how you can setup and run the automated tests. The automated tests should be run frequently, and must pass before releasing a new version.
To install you simply need to run the file named "unitTest". You will want to run it like this:
./unitTest install /location/to/.htpasswd
Note: If you already have phpunit installed, please remove the phpunit file from /usr/local/bin/ before running the installer. The installer will add a legacy version of phpunit (4.7.1) so there are no compatability issues when running the Selenium tests.
This will install everything that needs to be installed. It will install the selenium-server.jar, phpunit, add a testing user to your htpasswd file, and create a screenshots directory in test/screenshots as selenium will save screenshots so you can see where errors happened. It is safe to run the install function in the future as the script will only install, or add a new htpasswd entry if it does not exist. The script may prompt you to enter a password as sudo is required to run one of the commands.
At the end of the install you'll be asked to run an SQL query on your inventory database, please do this otherwise there will be errors when the tests run. This is simply adding the testing user to the database. The SQL query is given via the commandline, just copy and paste this into phpmyadmin or the mysql console.
To now run the unit testing you should do the following:
./unitTest run csThis will run the CS version of the tests.
./unitTest run mfcfThis will run the MFCF version of the tests.
./unitTest run allThis will run both CS and MFCF versions of the tests.
Please note: Firefox windows will pop up, this is normal! You can try to continue your work, however these windows will keep popping up so it is better if you don't try to. The tests will take about 6 minutes to run. If all of the tests fail and all of the errors look something like "CURL error while accessing the Selenium Server at..." then I suggest rerunning "./unitTest run" as sometimes the selenium server is slow to startup which means all of the selenium tests will not work. Running it again usually resolves the issue.
Note: If you get a php error about failing to open a stream relating to PHPunit files right at the top of the execution you can likely ignore these warnings.
When adding new test cases, there are a few conventions you must follow in order for PHPUnit/Selenium to recognize your new functions/tests.
When naming the PHP file that contains your tests, they must end in 'Test.php' otherwise PHPUnit will not run them. The files can be named anything you please, as long as the ending is correct.
Example: MyUsefulTest.php, InventorySearchTest.php
Inside of your newly created *Test.php file, you must create a class with the same name as the file. If my file is named 'MyUsefulTest.php', my class will be called 'MyUsefulTest'. Your class must also extend 'WebTestCase'. Example:
<?php class MyUsefulTest extends WebTestCase { //Testing functions go here } ?>
When writing your testing functions there is also a naming convention required for the tests to be executed by PHPUnit. Each test function must start with 'test'.
Example:
public function testVeryUsefulTest() { }
You can also write helper functions within your class, however you will want to omit the 'test' at the beginning of the function name otherwise PHPUnit will try to run it as a test.
Example:
//PHPUnit won't try to run this, but you can access it from your test functions. public function myHelperFunction() { } //PHPUnit will run this function, and you can use your helper functions within this. public function testVeryUsefulTest() { $this->myHelperFunction(); }
Note: The test functions are run from top to bottom within your class, and the classes (files inside functional/) are run in numerical order.
-- DanielAllen - 2015-04-01