This shows you the differences between two versions of the page.

Link to this comparison view

tutorial:testing [2015/02/20 11:08]
yarpheuil created
tutorial:testing [2015/10/05 17:52] (current)
Line 1: Line 1:
-How to test+<WRAP adihi><​html><​center></​html>​Adichatz provide an original and easy to use solution for testing UI components.<​html></​center></​html>​ 
 +  * Based on [[http://​www.testng.org|TestNG]] testing framework. 
 +  * Launched automatically or on-demand from application (Test classes can be updated and relaunched). 
 +  * Can easily simulate users actions. 
 +  * Results are displayed and interpretable in specific editor. 
 +==== How to test ==== 
 +=== Step 1: Add '​org.adichatz.testing'​ plugin === 
 +<columns 100% l> 
 +**org.adichatz.testing** plugin must be added to application environment. 
 +  * Open file <wrap adicode>​$projectDirectory/​META-INF/​MANIFEST.MF</​wrap>​. 
 +  * add line <wrap adicode>​org.adichatz.testing,</​wrap>​ in <wrap adicode>​Require-Bundle</​wrap>​ item. 
 +\\ \\ 
 +If you try to relaunch the application,​ an error must occur.\\ 
 +<​html><​span style="​color:​blue;​ font-family:​font-family:​ segoe UI, sans-serif; text-decoration:​ underline;"></​html><​hi #​DEDED6>​java.lang.RuntimeException</​hi><​html></​span></​html><​html><​span style="​font-family:​font-family:​ segoe UI, sans-serif;"></​html><​hi #​DEDED6>:​ No application id has been found.</​hi><​html></​span></​html>​ 
 +<​newcolumn l> 
 +{{add_testing_manifest.png?​250 |Add '​org.adichatz.testing'​ plugin}} 
 +<columns 100% l> 
 +To overcome this problem, follow instructions below: 
 +  * Select <wrap adicode>​Run > Run configurations...</​wrap>​. 
 +A new window is open, then: 
 +  * Select <wrap adicode>​Plug-ins</​wrap>​ tab. 
 +  * Select <wrap adicode>​Add Required Plug-ins</​wrap>​ button. 
 +  * In the same window, select <wrap adicode>​Run</​wrap>​ button. ​  
 +<​newcolumn l> 
 +{{add_required_plugins.png?​250 |Add required plugins}} 
 +\\ \\ 
 +=== Step 2: Create a Test class === 
 +<WRAP adihi>A test case is composed of one or several Java classes with one ore several annoted methods.\\ 
 +Below, a simple Test class is described. 
 +Create java class <wrap adicode>​MyFirstTest.java</​wrap>​ in package <wrap adicode>​org.mycompany.myproject.testing</​wrap>​. 
 +<sxh java; first-line: 1; highlight: [12, 15, 22]; title: excerpt from '​MyFirstTest.java'​ class.>​ 
 +package org.mycompany.myproject.testing;​ 
 +import org.adichatz.engine.e4.core.PartCore;​ 
 +import org.adichatz.engine.e4.part.BoundedPart;​ 
 +import org.adichatz.engine.e4.resource.E4SimulationTools;​ 
 +import org.adichatz.engine.simulation.SimulationTools;​ 
 +import org.adichatz.testing.AdiAssert;​ 
 +import org.adichatz.testing.TestingTools;​ 
 +import org.testng.annotations.Test;​ 
 +public class MyFirstTest { 
 + @Test 
 + public void test() { 
 + // Select Option queriesMenus/​filmQuery in navigator "​groupNavigator"​ and return a part. 
 + BoundedPart filmQueryPart = E4SimulationTools.handleNavigatorOpenPartItem("​groupNavigator",​ "​queriesMenu",​ "​filmQUERY"​);​ 
 + // check that part is active. 
 + AdiAssert.isPartActive(filmQueryPart);​ 
 + TestingTools.testInfo("​QueryForm with query '​filmQUERY'​ is active."​);​ 
 + PartCore filmQueryCore = filmQueryPart.getGenCode();​ 
 + // Launch query in filmQuery part. 
 + SimulationTools.handleContextMenuAction(filmQueryCore,​ "​tableCM:​contextMenu",​ "​launchQueryAction"​);​ 
 +<WRAP INDIC><​wrap adititle>​Remarks</​wrap>:​\\ 
 +This test opens a <wrap adicode>​QueryForm editor</​wrap>​ and launch a query to supply rows to the <wrap adicode> Table Controller</​wrap>​ contained in the editor.  
 +  * Line 12: <wrap adicode>​@Test</​wrap>​ annotation points out a method to be launched by TestNG. 
 +  * Line 15: Simulates selection of <wrap adicode>​Query Film</​wrap>​ in navigator. 
 +  * Line 22: Executes <wrap adicode>​launchQueryAction</​wrap>​ item in context menu. 
 +A more complex Test class which checks databinding between <wrap adicode> Entity editors</​wrap>​ could be seen [[testing_extensive|here]]. 
 +\\ \\ 
 +=== Step 3: Add entry to '​AdichatzRcpConfig.xml'​ file === 
 +<WRAP adihi>​You need to add an simple entry in file <wrap adicode>​$projectDirectory/​resources/​xml/​AdichatzRcpConfig.xml</​wrap>​ as shown below:</​WRAP>​ 
 +<sxh xml; first-line: 1; highlight: [15, 16, 17, 18, 19]; title: excerpt from '​AdichatzRcpConfig.xml'​ class.>​ 
 +<?xml version="​1.0"​ encoding="​UTF-8"​ standalone="​yes"?>​ 
 +<​adichatzRcpConfigTree xmlns:​xsi="​http://​www.w3.org/​2001/​XMLSchema-instance"​ xsi:​noNamespaceSchemaLocation="​http://​www.adichatz.org/​xsd/​v0.8.7/​engine/​adichatzRcpConfigTree.xsd">​ 
 +    <​rcpConfiguration>​ 
 +        <param id="​defaultQueryMaxResults"​ value="​200"/>​ 
 +        <param id="​defaultRefTextPopupURI"​ value="​adi://​org.adichatz.jpa/​common/​DefaultRefText"/>​ 
 +        <param id="​introPartURI"​ value="​bundleclass://​org.adichatz.engine/​org.adichatz.engine.intro.DefaultIntroPanel"/>​ 
 +        <param id="​introOutlineURI"​ value="​bundleclass://​org.adichatz.jpa/​org.adichatz.jpa.recent.RecentOutlinePage"/>​ 
 +        <​navigators>​ 
 +            <​navigator id="​groupNavigator"​ iconURI="​platform:/​plugin/​org.adichatz.engine.e4/​resources/​icons/​IMG_NAVIGATOR.png"​ contributionURI="​bundleclass://​org.adichatz.engine.e4/​org.adichatz.engine.e4.part.GroupNavigator"​ label="​adichatz.navigator"​ bundleURI="​adi://​org.adichatz.engine.e4/​./​adichatzEngineE4">​ 
 +                <​menuPath adiResourceURI="​adi://​myproject/​groupNavigator/​GroupNavigatorContent"/>​ 
 +                <​menuPath adiResourceURI="​adi://​org.adichatz.jpa/​./​JpaMenu"/>​ 
 +            </​navigator>​ 
 +        </​navigators>​ 
 +    </​rcpConfiguration>​ 
 +    <testing expanded="​true">​ 
 +        <suite id="​myFirstSuite"​ label="​Suite example"​ launchOnStartup="​false"​ expanded="​true">​ 
 +            <test id="​myFirstTest"​ label="​my first test" testURI="​bundleclass://​myproject/​org.mycompany.myproject.testing.MyFirstTest"/>​ 
 +        </​suite>​ 
 +    </​testing>​ 
 +<WRAP INDIC><​wrap adititle>​Remarks</​wrap>:​\\ 
 +A testing 
 +  * Line 15: <wrap adicode><​testing expanded="​true"></​wrap>​ means: A testing menu is added to existing navigators at runtime. The menu is expanded. 
 +  * Line 16: A suite test case is created. The suite is expanded and is not launched automatically during the application startup process. 
 +\\ \\ 
 +=== Step 4: Execute and reexecute tests === 
 +{{testing_execute.png |Execute a test}} 
 +<WRAP INDIC>To execute or reexecute a test case, click on the corresponding item (<wrap adicode>​my first test</​wrap>​). 
 +  * when a test fails, a specific editor was created for reporting test results and is automatically open. 
 +  * Changes done on Test classes in Eclipse IDE are directly considered without relaunching the application. 
 +\\ \\ 
 +=== Step 5: Show results === 
 +{{testing_results.png |Display Testing results}} 
 +<​html><​br clear="​all"></​html>​ 
 +<WRAP INDIC>A specific editor was created for reporting test results. By default, it is automatically open when a test fails. 
 +  * A tree is used to report results. 
 +    * Level <wrap adicode>​Run</​wrap>:​ Displays the label of the <wrap adicode>​suite</​wrap>​ or of the used <wrap adicode>​testNG xml</​wrap>​ file.  
 +    * Level <wrap adicode>​Suite</​wrap>:​ Displays <wrap adiCode>​onStart</​wrap>​ event with main features: duration, sucesses, failures....  
 +    * Level <wrap adicode>​Class</​wrap>:​ Display label for <wrap adicode>​class</​wrap>​ or <wrap adiCode>​onFinish</​wrap>​ event.  
 +    * Level <wrap adicode>​Test</​wrap>:​ Reports main features or the <wrap adicode>​Test</​wrap>​ (a method with annotation <wrap adicode>​@Test</​wrap>​):​ duration, sucesses, failures...  
 +  </​WRAP>​  
 +\\ \\ 
 +=== Tools === 
 +<WRAP adihi>​Testing menu provides Testing tools options</​wrap>​ as shown below:</​WRAP>​ 
 +{{testing_tools.png |Testing tools}} 
 +<WRAP indic> 
 +  * <wrap adicode>​Testing result manager</​wrap>:​ Opens and editor for reporting test results. 
 +  * <wrap adicode>​Display register for active editor</​wrap>:​ Display in the consol part all the entries of register for the active editor. These entries are used in Test class for naming controllers. 
 +  * <wrap adicode>​Refresh testing menu</​wrap>:​ Refresh current <wrap adicode>​Testing menu</​wrap>​. Changes made on IDE can be seen without having to quit the application. 
 +  ​
tutorial/testing.1424426934.txt.gz · Last modified: 2015/09/30 16:46 (external edit)