Automatic testing

Z Freenetis Wiki
Verze z 7. 6. 2014, 14:23, kterou vytvořil Sivosha (diskuse | příspěvky)
(rozdíl) ← Starší verze | zobrazit aktuální verzi (rozdíl) | Novější verze → (rozdíl)
Přejít na: navigace, hledání


Automated testing is used as feedback control of your actions developer.

Architecture tests

The tests are fully automated (You do not need testing program, but only deliver data to their testing) and automatically customizable changes in the source code.

Tests allow you to checkmodels,helpers andcontrollers, other parts of the system are checked only on their syntactic correctness.

Tests over unit tests do not compare the resulting values ​​of the function but only verify whether finished running error.

Tests are supported on *UNIX operating systems.

Retrieving information about the source code

Retrieving information about the source code is done automatically using a script that goes through all the subjects and obtained from them the necessary data to the calling routine subjects. These data are stored in a XML document ( / application / vendors / unit_tester / unit_testing_config.xml).


Installation tests

Installing the required libraries:

Ubuntu / Debian:

 sudo apt-get install curl perl libxml-writer-perl libxml-dom-perl

Fedora:

 sudo yum install curl perl perl-XML-Writer perl-XML-DOM php-xml

'The possibilities:'

 cd / var / www / freenetis
 chmod + x. / application / vendors / unit_tester / tester.sh

'Preventing sending e-mail/SMS etc.:'

Do config.php add:

 $ config ['unit_tester'] = TRUE;


Running tests

'Warning: Test Run only on the local development server!'

 cd / var / www / freenetis / application / vendors / unit_tester
 . / tester.sh <URL> <LOGIN_NAME> <PASSWORD>

Note: The running time of all tests on Intel Core i5 2.53GHz with Ubuntu 11.04 is about four minutes.

'Example with arguments'

 . / tester.sh-o http://localhost/freenetis admin 123456


Arguments test script

 $. / Tester.sh - help
 Script for testing FreenetIS
 USAGE: tester.sh [options] URL username password

 Options:
  -o, - open-browser    Opens browser with models or helpers errors
                     automatically, after error detection.
  -s, - skip-syntax        Skip syntax check of all files
  -m, - skip-models     Skip test of models
  -h, - skip-helpers      Skip test of helpers
  -c, - skip-controllers Skip test of controllers
  -e, - enable-stats      Turn on statistics and benchmarks

Editing tested information

Automatically generated test values ​​are not sufficient for testing, so it is appropriate to add some additional value.

For example, indicate the model in the configuration file, find the relevant entity (as the title tag and attribute names).

'Model been automatically generated:'

 <Model name="test">
 <method name="testovaci_funkce" autogenerate="on">
     <attributes>
         <attribute name="user_id" default_value="" />
         <attribute name="filter_values" default_value="array()" />
     </ attributes>
     <values>
         <input>
             value="" /> <param
             value="array()" /> <param
         </ input>
     </ values​​>
 </ method>
 </ model>

Very important is the attribute method 'autogenerate if you make changes in the method and made it to 'off changes when you start testing discarded.


Tag 'input' can be understood as a set of test values ​​of the method.

'If you do not want that method has been tested at all (common with methods that depend on objects, or insert data into the database), this can be achieved as follows:'

<model name="test">

    <method name="testovaci_funkce" autogenerate="off">
        <attributes>
            <attribute name="user_id" default_value="" />
            <attribute name="filter_values" default_value="array()" />
        </attributes>
        <values>
        </values>
    </method>
</model>


'Ideal test data (trying to insert an empty and meaningless and value) for our test model might look like this:'

<model name="test">

    <method name="testovaci_funkce" autogenerate="off">
        <attributes>
            <attribute name="user_id" default_value="" />
            <attribute name="filter_values" default_value="array()" />
        </attributes>
        <values>
            <input>
                <param value="" />
                <param value="" />
            </input>
            <input>
                <param value="" />
                <param value="array()" />
            </input>
            <input>
                <param value="1" />
                <param value="array('id' => '1')" />
            </input>
            <input>
                <param value="abd'se$#@`" />
                <param value="abd'se$#@`" />
            </input>
            <input>
                <param value="1" />
                <param value="array('id' => '1sef%se@š`', 'Ijnfsief' => 'se2', 'sef$a;!')" />
            </input>
        </values>
    </method>
</model>


Additional features for controllers

The controllers can also send data using POST and HTTP GET action, just to test the input parameters add parameters in the form:

<param name="post_name" type="post" value="hodnota" />
<param name="get_name" type="get" value="hodnota" />


After-editing tested validity of the document

After each editing the configuration file, you should check its validity using the supplied DTD ( / application / vendors / unit_tester / unit_testing_config.xml) as the test itself allows for valid configurations!

In Netbeans IDE validity checking done by marking the configuration file and then invoke the context menu items and Validate XML.


Statistics and benchmarks

The tests are tools for benchmarking models and controllers. They can be turned on using the parameter -e </ code>.

The results of benchmark models is displayed in the output HTML file, along with the tests.

Results for the controllers are stored in a file <code> curl / cstats </ code>, which has four columns separated by a tab.

  • The first column contains the information about the time of the controller in seconds.
  • The second column shows memory consumption in MB for the implementation.
  • The third column is the URL request.
  • The fourth includes the HTTP POST sent controller.

Example hits the 10 requirements with the largest memory consumption:

 cat curl / cstats | cut-f 1,2,3 | sort-n-r-k 2,2 | head-n 10

Note: Throughout this manual is considered the path to FreenetIS derived from Installation FreenetIS