Inventory Developer Test Plan

Overview

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 Testing

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.

Requirements

  • Google Chrome or Firefox
  • Selenium IDE Extension (Chrome) or Add-on (Firefox)
  • The testing suite save file -- Stored in test/ as inventory-testing.side.

Installing/Setup

There is not a lot to do in terms of installation. Once you have the extension you can open the extension via the button it added to the browser. You'll have a prompt pop up where you can choose to open an existing project. Choose the file stored in the inventory repo test/inventory-testing.side. You will see a bunch of "Test suites", they are broken up into categories, and then also in an "All Tests" suite. Be sure to change the base URL you see at the top. It will likely be something like "http://scspc806.cs.uwaterloo.ca/inv". You'll want to change this to reflect your machines address and where inventory is stored. You can run tests as a suite, independently, or by running the "All Tests" suite. Simply open the "All Tests" suite of tests and click the run all tests in suite button.

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.

Adding New Tests

If you want to add new tests you can do this fairly easily. Switch to the tests screen (CTRL + 1) and click the plus button to add a new test. You can then simply hit the "REC" button to record a new test. Sometimes extra clicks or steps are recorded that you can eliminate manually. After making the test you will want to be sure to add various assertions to test the code. If this isn't making sense just look at the other tests for examples of how the assertions work.

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.

Old Testing Documentation

Automated Testing

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.

Requirements

  • Java installed
  • Firefox installed
  • PHPUnit (explained below)
  • Selenium Server (already in git, explained below)

Installing/Setup/Running

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 cs
This will run the CS version of the tests.
./unitTest run mfcf
This will run the MFCF version of the tests.
./unitTest run all
This 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.

Adding New Test Cases

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

Edit | Attach | Watch | Print version | History: r19 < r18 < r17 < r16 < r15 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r19 - 2019-08-02 - JustinVisser
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback