Difference between revisions of "GXUnit User Guide"

From GXtest Wiki
Jump to: navigation, search
(Initializing GXUnit)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
GXUnit User Guide
 
GXUnit User Guide
  
 
+
{{Idiomas|GXUnit|GXUnit User Guide|GXUnit User Guide}}
 
== Introduction ==
 
== Introduction ==
  
Line 32: Line 32:
 
[[image:GXunit_installation2.png|center]]   
 
[[image:GXunit_installation2.png|center]]   
  
En esta pantalla se listan todas las instalaciones de GeneXus detectadas por el instalador. Si su instalación de GeneXus no se encuentra en la lista puede seleccionar a mano la carpeta donde se encuentra el archivo GeneXus.exe
+
All detected Genexus installations are listed in this screen. If your installation is not listed, you can manually select the path of the GeneXus.exe file.
  
 
[[image:GXunit_installation3.png|center]]   
 
[[image:GXunit_installation3.png|center]]   
Line 46: Line 46:
 
[[image:GXunit_create.png|center]]
 
[[image:GXunit_create.png|center]]
  
=== Deleting a GXUnit object ===
+
=== Deleting GXUnit's objects ===
  
  
There is a feature available in the menu, which deletes all of the objects related with GXUnit, including all of the objects of the type TestCase as well as Suites having been created.
+
There is a feature available in the menu, which deletes all objects related with GXUnit, including objects of the type TestCase as well as Suites having been created.
  
 
   
 
   
Line 55: Line 55:
 
 
  
== Tool window GXUnit ==
+
== GXUnit's Tool window ==
  
  
In order to work with the tool, 'tool window GXUnit' must be enabled. From that tool, we may see all the test suites, as well as all of the test cases which were defined.
+
In order to work with GXUnit, 'tool window' must be enabled. From that tool, we may see all the test suites, as well as all of the test cases which were defined.
  
  
Line 67: Line 67:
  
  
Una suite de pruebas tiene la funcionalidad de agrupar cierto conjunto de Casos de prueba según el criterio del usuario. Para crear una nueva Suite de Pruebas se debe hacer click derecho sobre una suite ya creada o sobre cualquier lugar de la tool window GXUnit para crear una Suite del primer Nivel.
+
A Test Suite is a set of Test Cases, grouped according to a specific end-users' criteria. Creating a new test suite is a simple process, with either just a right click on top of one of the already existing test suites or, clicking anywhere in the GXUnit's tool window so that a first level suite is created.
  
 
   [[image:GXunit_suite1.png|center]]
 
   [[image:GXunit_suite1.png|center]]
  
Luego de seleccionar Nueva Suite se pide el nombre de la misma y al ingresarlo se crea una nueva Folder GeneXus bajo la estructura Objects/GXUnitSuites.
+
After selecting the 'New Test Suite' option, its name is asked and after inserting it a new 'Folder GeneXus' is created under the 'Objects/GXUnitSuites' structure.
  
 
   
 
   
Line 80: Line 80:
  
  
Para crear un nuevo Caso de Prueba se presiona Click derecho en una Suite y se selecciona Nuevo TestCase. En el cuadro de dialogo de nuevo objeto GeneXus se debe seleccionar el objeto TestCase y como Folder queda seleccionada la Suite elegida.
+
When creating a new Test Case, right click on a Test Suite and select New Test Case. In the dialog box for the GeneXus object, choose the option related to Test Case, afterwards, select Test Suite to be the destination folder for it.
  
[[image:GXunit_create1.png|center]]
+
  [[image:GXunit_create1.png|center]]
  
Al crear un nuevo objeto de este tipo se pregunta a qué objeto está asociado. En esta versión se permiten seleccionar objetos Procedure, DataProvider o Transaction.
+
When creating a new object of this type, it is necessary to establish the object it is associated with. In this version the following objects may be selected Procedures, DataProvider, Transactions.
  
 
   [[image:GXunit_create2.png|center]]
 
   [[image:GXunit_create2.png|center]]
  
El objeto TestCase tendrá un editor donde se podrá utilizar la sintaxis del objeto Procedimiento para llamar a cualquier otro objeto GX, y realizar las comparaciones llamando a los objetos de tipo Assert que se describen más adelante.
+
The object Test Case will have an editor, which will support the syntax of the object Procedure for invoking any other GeneXus' object, after which, it will run certain comparisons invoking the object of the type Assert, also described in this document.
Al crearse un caso de prueba se genera automáticamente código GeneXus por defecto donde se llama al objeto a probar y se realizan asserts para evaluar los resultados de dicha llamada. El objetivo es modificar este código para que se adapte a las necesidades del usuario.
+
As a new Test Case is created, GeneXus code is automatically generated where the object under test is invoked, and some asserts are conducted in order to evaluate the results obtained. The objective is modifying this code so that it will meet the users needs.  
  
  
Line 95: Line 95:
  
  
Para el caso de que el objeto asociado al caso de prueba sea un Procedimiento se crea una variable por cada una que se encuentre en la regla “Parm” del procedimiento a probar y según su tipo, si es de entrada o entrada/salida se inicializa con un valor por defecto o si es de salida o entrada/salida se evalúa con una llamada a un Assert (según el tipo).
+
In the event that the object associated to the Test Cases is a procedure, then a variable is created for each one of them in the rule "Parm" found in the procedure under test. Also, and depending on it being either input or input/output, it may be initialized with a default value, or evaluated with an Assert.
 +
 
  
 
[[image:GXunit_procedure.png|center]]
 
[[image:GXunit_procedure.png|center]]
Line 103: Line 104:
  
  
Al crear un nuevo caso de prueba asociado a una transacción con la propiedad Business Component se genera código genexus por defecto de la siguiente manera:
+
Whilst creating a new test case associated to a Transaction with the property Business Component, GeneXus' code is generated by default in the following manner::
 
+
*Se define una variable del tipo de la transacción BC
+
*Inicializa con un valor por defecto todos los atributos
+
*Guarda los datos (save del BC)
+
*Carga los datos (load del BC)
+
*Se realiza un assert para cada mensaje de la Transacción
+
*Se realiza un assert por cada atributo del Business Component
+
  
 +
*A variable of the type transaction BC is defined
 +
*Afterwards, it is initialised with a default value for all of the attributes
 +
*Saves the data
 +
*Loads the data
 +
*For each message of the Transaction an assert is conducted
 +
*For each Business Component attribute an assert is conducted
  
 
[[image:GXunit_assertBC.png|center]]
 
[[image:GXunit_assertBC.png|center]]
Line 118: Line 118:
  
  
Al crear un nuevo caso de prueba asociado a un Data Provider se genera código genexus por defecto de la siguiente manera:
+
Whilst creating a new test case associated to a Data Provider, Genexus' code is generated by default in the following manner:
  
*Se inicializan los parámetros de entrada del DP
+
*The input parameters fo the DP are initialized
*Se invoca al DP
+
*Afterwards, the Data Provider is invoked
*Se inicializa el resultado esperado (BC o SDT)
+
*The expected result is initialized (BC o SDT)
*Se realiza un AssertStringEquals para comparar el Output esperado con el obtenido
+
*In order to compare the expect output against the obtained, an AssertStringEquals is performed
  
  
Line 131: Line 131:
  
  
Los métodos de tipo Assert son utilizados para comparar los resultados de la ejecución de objetos bajo prueba con los resultados que se esperan de dichos objetos. Fueron implementados como Procedimientos GeneXus. Se proveerán dos de estos métodos, AssertNumericEquals y AssertStringEquals, para comparar variables numéricas y cadenas de caracteres respectivamente. Estos procedimientos son creados al inicializarse GXUnit y forman parte de la KB.
+
The Assert methods are employed to compare the results obtained after running the objects under test, against the expected results for the very same objects. The following two methods are provided, AssertNumericEquals and AssertStringEquals, so that variables of the type number as well as, variables of the type strings can be compared respectively. Those procedures are created when GXUnit is initialized and are part of the KB.  
 
+
Al ejecutarse uno de estos métodos se irán guardando los resultados para luego poder visualizar todos los resultados de la ejecución de los casos de prueba.
+
  
 +
When running one of those methods, the results will be saved for later evaluation of the results obtained from the executed tests.
 
 
  
Line 140: Line 139:
  
  
La tool window contiene los conjuntos de Casos de Prueba agrupados en sus respectivas Suites.
+
The GXUnit's tool window contains all the sets of Test Cases grouped together in its respective Test Suites.
  
 
[[image:GXunit_execution.png|center]]
 
[[image:GXunit_execution.png|center]]
  
  
Seleccionando los casos de prueba que quieren ser ejecutados (mediante su check box) al presionar botón “Test” se creará un nuevo procedimiento (RunnerProcedure) que tendrá las llamadas a todos los tests a correr, se generarán todos los objetos necesarios y se ejecutarán.
+
Ticking on the checkbox corresponding to a test case, will select it for executing it, after which, pressing on the button "Test" will create a new procedure named 'RunnerProcedure'. The previously mentioned procedure will have calls to all the tests to be executed, as well as have generated all of the necessary objects.
 
+
  
 
=== Seeing the Results ===
 
=== Seeing the Results ===
  
  
Luego de ejecutados los casos de prueba se crea un objeto Resultado donde quedará registro del resultado de la prueba. Este objeto tendrá como nombre la fecha y hora de ejecución. En el cabezal se muestra los tests ejecutados y la cantidad de ellos que fallaron. Los Asserts que fallen se mostrarán en rojo con el detalle de la falla y los que se completen satisfactoriamente se mostrarán en verde.
+
After having executed all of the test cases, an object of the type Result is created, which will save and store the results from the tests conducted. That object will be created with the execution date and time in its name. In the header the tests executed are displayed, along with the amount of failed ones. The Asserts which fail, will be shown in red with the detail for failure, whereas those tests successfully completing its execution will be shown in green.
  
 
[[image:GXunit_results.png|center]]
 
[[image:GXunit_results.png|center]]
  
== Explorting and Importing Test Cases as well as Results ==
+
== Exporting and Importing Test Cases as well as Results ==
  
  
Tanto los Test Case, Suites como objetos Resultado se pueden exportar e importar entre las distintas Bases de Conocimiento que tengan instalada la herramienta como cualquier otro objeto GeneXus.
+
Test Cases, Test Suites as well as objects Result, can be exported and imported across the different knowledge bases installed in the tool, just as it happens with any other GeneXus object.
 
+
  
 
== Running tests using MSBuild tasks ==
 
== Running tests using MSBuild tasks ==
  
  
En la dll GXUnit.dll que se encuentra en la carpeta “Directorio de instalación de GeneXus\Packages” están definidas dos tareas MSBuild (GenerateGXUnitTests y GenerateGXUnitResults) para poder realizar la ejecución de las pruebas desde un script MSBuild. Para usarlas hay que importarlas en el script MSBuild.
+
In GXUnit.dll, which can be located in the following directory "<GeneXus installation directory>\Packages", two MSBuild tasks are defined, such as, GenerateGXUnitTests and GenerateGXUnitResults so that all of the tests can be executed from an MSBuild script. For using them, those need to be imported in the MSBuild script.
 
+
An example for using tasks, as well as using tasks defined by GeneXus, is the following one:
Un ejemplo de uso de las tareas, usando también tareas definidas por GeneXus, es el siguiente:
+
  
 
<Target Name="GXUnit"> <BR>
 
<Target Name="GXUnit"> <BR>

Latest revision as of 14:06, 12 June 2014

GXUnit User Guide

Spanish.gif
English.gif
Japan.gif

Contents

Introduction

This document aims at displaying the core features available through GXUnit, the Genexus' unit testing tool.

In the following page, you will find the following How to's:

  • Installing GXUnit
  • Creating your unit tests
  • Running tests in an interactive manner and seeing the results
  • Running your tests with a batch (msbuild)

Installation

GXUnit is free and can be downloaded from GeneXus' marketplace.

Installer

Next you will be shown with the necessary steps for installing GXUnit.

Installer windows:

  1. Welcome screen
  2. License agreement
  3. Selecting your GeneXus installation
  4. Ready for installing it
GXunit installation1.png
GXunit installation2.png

All detected Genexus installations are listed in this screen. If your installation is not listed, you can manually select the path of the GeneXus.exe file.

GXunit installation3.png


GXunit installation4.png

Initializing GXUnit

In order to initialize GXUnit, it must be done from an option available in the GXUnit menu. By proceeding in that way, the set of necessary objects for employing them with the tool will be created. The aforementioned objects are placed in a directory named GXUnit, underneath the objects' tree.

GXunit create.png

Deleting GXUnit's objects

There is a feature available in the menu, which deletes all objects related with GXUnit, including objects of the type TestCase as well as Suites having been created.


GXunit delete.png

GXUnit's Tool window

In order to work with GXUnit, 'tool window' must be enabled. From that tool, we may see all the test suites, as well as all of the test cases which were defined.


GXunit toolWindow.png

Test Suite

A Test Suite is a set of Test Cases, grouped according to a specific end-users' criteria. Creating a new test suite is a simple process, with either just a right click on top of one of the already existing test suites or, clicking anywhere in the GXUnit's tool window so that a first level suite is created.

GXunit suite1.png

After selecting the 'New Test Suite' option, its name is asked and after inserting it a new 'Folder GeneXus' is created under the 'Objects/GXUnitSuites' structure.


GXunit suite2.png

Test Case

When creating a new Test Case, right click on a Test Suite and select New Test Case. In the dialog box for the GeneXus object, choose the option related to Test Case, afterwards, select Test Suite to be the destination folder for it.

GXunit create1.png

When creating a new object of this type, it is necessary to establish the object it is associated with. In this version the following objects may be selected Procedures, DataProvider, Transactions.

GXunit create2.png

The object Test Case will have an editor, which will support the syntax of the object Procedure for invoking any other GeneXus' object, after which, it will run certain comparisons invoking the object of the type Assert, also described in this document. As a new Test Case is created, GeneXus code is automatically generated where the object under test is invoked, and some asserts are conducted in order to evaluate the results obtained. The objective is modifying this code so that it will meet the users needs.


GeneXus Procedures Testing

In the event that the object associated to the Test Cases is a procedure, then a variable is created for each one of them in the rule "Parm" found in the procedure under test. Also, and depending on it being either input or input/output, it may be initialized with a default value, or evaluated with an Assert.


GXunit procedure.png


Transactions Testing (BC)

Whilst creating a new test case associated to a Transaction with the property Business Component, GeneXus' code is generated by default in the following manner::

  • A variable of the type transaction BC is defined
  • Afterwards, it is initialised with a default value for all of the attributes
  • Saves the data
  • Loads the data
  • For each message of the Transaction an assert is conducted
  • For each Business Component attribute an assert is conducted
GXunit assertBC.png

Data Providers Testing

Whilst creating a new test case associated to a Data Provider, Genexus' code is generated by default in the following manner:

  • The input parameters fo the DP are initialized
  • Afterwards, the Data Provider is invoked
  • The expected result is initialized (BC o SDT)
  • In order to compare the expect output against the obtained, an AssertStringEquals is performed


GXunit assertstringeq.png

Asserts

The Assert methods are employed to compare the results obtained after running the objects under test, against the expected results for the very same objects. The following two methods are provided, AssertNumericEquals and AssertStringEquals, so that variables of the type number as well as, variables of the type strings can be compared respectively. Those procedures are created when GXUnit is initialized and are part of the KB.

When running one of those methods, the results will be saved for later evaluation of the results obtained from the executed tests.  

Running Test Cases

The GXUnit's tool window contains all the sets of Test Cases grouped together in its respective Test Suites.

GXunit execution.png


Ticking on the checkbox corresponding to a test case, will select it for executing it, after which, pressing on the button "Test" will create a new procedure named 'RunnerProcedure'. The previously mentioned procedure will have calls to all the tests to be executed, as well as have generated all of the necessary objects.

Seeing the Results

After having executed all of the test cases, an object of the type Result is created, which will save and store the results from the tests conducted. That object will be created with the execution date and time in its name. In the header the tests executed are displayed, along with the amount of failed ones. The Asserts which fail, will be shown in red with the detail for failure, whereas those tests successfully completing its execution will be shown in green.

GXunit results.png

Exporting and Importing Test Cases as well as Results

Test Cases, Test Suites as well as objects Result, can be exported and imported across the different knowledge bases installed in the tool, just as it happens with any other GeneXus object.

Running tests using MSBuild tasks

In GXUnit.dll, which can be located in the following directory "<GeneXus installation directory>\Packages", two MSBuild tasks are defined, such as, GenerateGXUnitTests and GenerateGXUnitResults so that all of the tests can be executed from an MSBuild script. For using them, those need to be imported in the MSBuild script. An example for using tasks, as well as using tasks defined by GeneXus, is the following one:

<Target Name="GXUnit">
<OpenKnowledgeBase Directory="Path a la KB"/>
<GenerateGXUnitTests>
<Output TaskParameter="XMLName" PropertyName="XMLName" />
</GenerateGXUnitTests>
<BuildOne ObjectName="RunnerProcedure" ForceRebuild="true" />
<Run ObjectName="RunnerProcedure" />
<GenerateGXUnitResults XMLName="$(XMLName)"/>
<CloseKnowledgeBase />
</Target>