Differences
This shows you the differences between two versions of the page.
tutorial:testing [2020/04/27 10:12] |
tutorial:testing [2020/04/27 10:12] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | <WRAP adihi><html><center></html>Adichatz provides an original and easy to use solution for testing UI components.<html></center></html> | ||
+ | * Based on [[http://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. | ||
+ | </WRAP> | ||
+ | \\ | ||
+ | ==== 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> | ||
+ | {{tutorial:add_testing_manifest.png?400 |Add 'org.adichatz.testing' plugin}} | ||
+ | </columns> | ||
+ | <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> | ||
+ | {{tutorial:add_required_plugins.png?500 |Add required plugins}} | ||
+ | </columns> | ||
+ | <WRAP indic><wrap adititle>Remark</wrap>:\\ | ||
+ | An other way is to add missing plugins inside <wrap adicode>{plugin}/{projectName}.product</wrap> file: | ||
+ | * <wrap adicode>com.google.inject</wrap>, | ||
+ | * <wrap adicode>org.apache.ant</wrap>. | ||
+ | If you decide to add missing plugins inside <wrap adicode>{plugin}/{projectName}.product</wrap> file, thing to delete these lines before exporting project. | ||
+ | </WRAP> | ||
+ | \\ \\ | ||
+ | === 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. | ||
+ | </WRAP> | ||
+ | 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"); | ||
+ | } | ||
+ | } | ||
+ | </sxh> | ||
+ | <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]]. | ||
+ | </WRAP> | ||
+ | \\ \\ | ||
+ | === Step 3: Create a file $projectDirectory/resources/xml/AdichatzTesting.xml as follow === | ||
+ | <WRAP adihi>You need to add an simple entry in file <wrap adicode>$projectDirectory/resources/xml/AdichatzTesting.xml</wrap> as shown below:</WRAP> | ||
+ | <sxh xml; first-line: 1; highlight: [2, 3, 4, 5, 6]; title: excerpt from 'AdichatzTesting.xml' class.> | ||
+ | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
+ | <adichatzTestingTree expanded="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adichatz.org/xsd/v0.9.1/testing/adichatzTestingTree.xsd"> | ||
+ | <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> | ||
+ | </adichatzTestingTree> | ||
+ | </sxh> | ||
+ | <WRAP indic><wrap adititle>Remarks</wrap>:\\ | ||
+ | A testing | ||
+ | * Line 1: <wrap adicode><adichatzTestingTree expanded="true"...</wrap> means: A testing menu is added to existing navigators at runtime. The menu is expanded. | ||
+ | * Line 2: A suite test case is created. The suite is expanded and is not launched automatically during the application startup process. | ||
+ | </WRAP> | ||
+ | \\ \\ | ||
+ | === Step 4: Execute and reexecute tests === | ||
+ | {{tutorial:testing_execute.png?400 |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. | ||
+ | </WRAP> | ||
+ | \\ \\ | ||
+ | === Step 5: Show results === | ||
+ | {{tutorial:testing_results.png?600 |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> | ||
+ | {{tutorial:testing_tools.png?600 |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. | ||
+ | . | ||
+ | </WRAP> | ||
+ | |