Jump to: navigation, search

Difference between revisions of "EDT:EUnit Testing"

Line 3: Line 3:
 
*What is EUnit<br>
 
*What is EUnit<br>
  
EUnit stands for EGL Unit testing framework. It is a simple open source framework to write and run repeatable EGL tests. <br>
+
EUnit stands for EGL Unit testing framework. It is a simple open source framework to write and run repeatable EGL tests. <br>  
  
Its features include:<br>
+
Its features include:<br>  
  
 
*Tooling to generate test runner and run the test cases – Provided by EDT Framework  
 
*Tooling to generate test runner and run the test cases – Provided by EDT Framework  
 
**Manually and Automated  
 
**Manually and Automated  
**Can be run as often as needed (on demand, nightly build)  
+
**Can be run as often as needed (on demand, nightly build, etc.)  
 
**GUI and command line interfaces  
 
**GUI and command line interfaces  
 
**Logging, Reporting, Analyzing  
 
**Logging, Reporting, Analyzing  
**Can be used in multiple language environment (java, javascript, etc)<br>
+
**Can be used in a multiple language environment (java, javascript, etc)<br>
  
*Test Cases - Provided by test writters<br>
+
*Test Cases - Provided by test writters<br>  
*Documentation - Provided by <br>
+
*Documentation - Provided by <br>  
 
**What does each test case test<br>
 
**What does each test case test<br>
  
Line 22: Line 22:
 
== How to write test cases using EUnit<br>  ==
 
== How to write test cases using EUnit<br>  ==
  
1. Create an EGL Project, for example: eunit.test<br>  
+
1. Create an EGL Project, for example: '''eunit.test'''<br>  
  
*Select "Basic" as the template.<br>
+
*Select '''Basic''' as the template.<br>
  
[[Image:Eunit001.JPG]]
+
[[Image:Eunit001.JPG]]  
  
 
*Set the generators:<br>
 
*Set the generators:<br>
  
&nbsp; &nbsp; 1) If you run the testing on both Java and JavaScript platform, just leave the settings as default. That is, turn on both Java and JavaScript generator.<br>  
+
&nbsp; &nbsp; 1) If you run the testing on both Java and JavaScript platform, just leave the default settings (both Java and JavaScript generator selected).<br>  
  
&nbsp; &nbsp; 2) If you run the testing on a specific platform, select the checkbox "Override generation settings from workspace preferences" and choose a generator.<br>  
+
&nbsp; &nbsp; 2) If you run the testing on a specific platform, select '''Override generation settings from workspace preferences''' and choose a generator.<br>  
  
[[Image:Eunit002.JPG]]
+
[[Image:Eunit002.JPG]]  
  
2. Create an EGL Library, for example: test, and give a package name "libs".<br>  
+
2. Create an EGL Library, for example: '''test,''' and give a package name '''libs'''.<br>  
  
[[Image:Eunit003.JPG]]
+
[[Image:Eunit003.JPG]]  
  
3. Open the library with EGL Editor, remove the automatically generated code.<br>  
+
3. Open the library with the EGL Editor, and remove the automatically generated code.<br>  
  
4. Type the variable declarations and functions(We treat each function as an EUnit test case) in the library, which should contains the annotation @Test. For example:<br>  
+
4. Type the variable declarations and functions (we treat each function as an EUnit test case) in the library, which should contain the annotation '''@Test'''. For example:<br>  
 
<pre>package libs;
 
<pre>package libs;
 
import org.eclipse.edt.eunit.runtime.LogResult;
 
import org.eclipse.edt.eunit.runtime.LogResult;
Line 63: Line 63:
 
*Tips<br>
 
*Tips<br>
  
&nbsp;&nbsp;&nbsp; If you want to disable some specific test cases, you can use "targetLang" in the annotation. For example, below is a test case which cannot be generated into JavaScript.<br>  
+
&nbsp;&nbsp;&nbsp; If you want to disable some specific test cases, you can use '''targetLang''' in the annotation. For example, below is a test case which cannot be generated into JavaScript.<br>  
 
<pre>function runAssignmentFunction01(){@Test {targetLang = [JAVA]}}
 
<pre>function runAssignmentFunction01(){@Test {targetLang = [JAVA]}}
 
variation = "constant initialization";
 
variation = "constant initialization";
 
LogResult.assertStringEqual1("Fred Smith", constFlexName);
 
LogResult.assertStringEqual1("Fred Smith", constFlexName);
 
end
 
end
</pre>
+
</pre>  
 
+
 
== How to run tests using EUnit<br>  ==
 
== How to run tests using EUnit<br>  ==
  
 
*'''Java'''<br>
 
*'''Java'''<br>
  
1. Right click on the project you just created, choose Generate EGL Test Driver =&gt; Java to create the java test driver.<br>  
+
1. Right click on the project you just created, and choose '''Generate EGL Test Driver &gt; Java''' to create the Java test driver.<br>  
  
 
[[Image:Eunit004.JPG]]  
 
[[Image:Eunit004.JPG]]  
  
2. Go to project eunit.test.eunit.java =&gt; folder generatedJava =&gt; Run test.RunAllTests_pgm as Java application.  
+
2. Go to '''project eunit.test.eunit.java &gt; folder generatedJava &gt; Run test.RunAllTests_pgm as Java application'''.  
  
3. Refresh project eunit.test.eunit.java, you should see a new folder "ResultRoot", expand its subfolder (name is in current timestamp yyyymmdd_hhmmss), till you see file "ResultSummary.trs", double click to open this file. You need to install Eclipse BIRT to view the Test Result Statistics Chart. You can also go through every individual report by clicking the leaf node of the result tree and navigate to the corresponding source file.<br>  
+
3. Refresh '''project eunit.test.eunit.java'''.&nbsp; You should see a new folder,&nbsp; '''ResultRoot'''.&nbsp; Expand its subfolder (name is in current timestamp yyyymmdd_hhmmss), until you see file '''ResultSummary.trs'''.&nbsp; Double click to open this file. You need to install Eclipse BIRT to view the Test Result Statistics Chart. You can also go through every individual report by clicking the leaf node of the result tree and navigating to the corresponding source file.<br>  
  
[[Image:Eunit005.JPG]]
+
[[Image:Eunit005.JPG]]  
  
 
*Tips<br>
 
*Tips<br>
  
You can also select one or more packages, egl files (must be the same type) to generate test driver, instead of the entire EGL project. <br>  
+
You can also select one or more packages, egl files (they must be the same type) to generate the test driver, instead of the entire EGL project. <br>  
  
 
*'''JavaScript'''
 
*'''JavaScript'''
  
1. Right click on the project you just created, choose Generate EGL Test Driver =&gt; JavaScript to create the JavaScript test driver. <br>  
+
1. Right click on the project you just created, and choose '''Generate EGL Test Driver &gt; JavaScrip'''t to create the JavaScript test driver. <br>  
  
2. There are two ways to execute the testing:<br>  
+
2. There are two ways to execute the test:<br>  
  
*Go to project eunit.test.eunit.javascript =&gt; EGLSource =&gt; eunitgen.RunAllTests_rui.egl, open in EGL Rich UI editor's preview pane, execute it  
+
*Go to '''project eunit.test.eunit.javascript &gt; EGLSource &gt; eunitgen.RunAllTests_rui.egl''', open it in EGL Rich UI editor's preview pane, and execute it  
*Go to project eunit.test.eunit.javascript =&gt; EGLSource =&gt; deploy eunit_test_eunit_javascript.egldd file to a target project. Start the server and then run the html file in the browser.<br>
+
*Go to '''project eunit.test.eunit.javascript &gt; EGLSource &gt; deploy eunit_test_eunit_javascript.egldd file to a target project.''' Start the server and then run the html file in the browser.<br>
  
3. Refresh project eunit.test.eunit.javascript, you should see a new folder "ResultRoot", do the same steps as described in the Java section above.<br>  
+
3. Refresh '''project eunit.test.eunit.javascript'''.&nbsp; You should see a new folder, '''ResultRoot''',.&nbsp; Then do the same steps as described in the Java section above.<br>  
  
 
<br>  
 
<br>  

Revision as of 17:22, 20 January 2012

EUnit Test Framework Overview

  • What is EUnit

EUnit stands for EGL Unit testing framework. It is a simple open source framework to write and run repeatable EGL tests.

Its features include:

  • Tooling to generate test runner and run the test cases – Provided by EDT Framework
    • Manually and Automated
    • Can be run as often as needed (on demand, nightly build, etc.)
    • GUI and command line interfaces
    • Logging, Reporting, Analyzing
    • Can be used in a multiple language environment (java, javascript, etc)
  • Test Cases - Provided by test writters
  • Documentation - Provided by
    • What does each test case test

Design

How to write test cases using EUnit

1. Create an EGL Project, for example: eunit.test

  • Select Basic as the template.

Eunit001.JPG

  • Set the generators:

    1) If you run the testing on both Java and JavaScript platform, just leave the default settings (both Java and JavaScript generator selected).

    2) If you run the testing on a specific platform, select Override generation settings from workspace preferences and choose a generator.

Eunit002.JPG

2. Create an EGL Library, for example: test, and give a package name libs.

Eunit003.JPG

3. Open the library with the EGL Editor, and remove the automatically generated code.

4. Type the variable declarations and functions (we treat each function as an EUnit test case) in the library, which should contain the annotation @Test. For example:

package libs;
import org.eclipse.edt.eunit.runtime.LogResult;
import org.eclipse.edt.eunit.runtime.Test;

// basic library
library test
	
	const constFlexName string = "Fred Smith";
	varFlexName string;
	variation string;
	
	function runAssignmentFunction01(){@Test {}}
		variation = "constant initialization";
		LogResult.assertStringEqual1("Fred Smith", constFlexName);
	end
	
end
  • Tips

    If you want to disable some specific test cases, you can use targetLang in the annotation. For example, below is a test case which cannot be generated into JavaScript.

function runAssignmentFunction01(){@Test {targetLang = [JAVA]}}
	variation = "constant initialization";
	LogResult.assertStringEqual1("Fred Smith", constFlexName);
end

How to run tests using EUnit

  • Java

1. Right click on the project you just created, and choose Generate EGL Test Driver > Java to create the Java test driver.

Eunit004.JPG

2. Go to project eunit.test.eunit.java > folder generatedJava > Run test.RunAllTests_pgm as Java application.

3. Refresh project eunit.test.eunit.java.  You should see a new folder,  ResultRoot.  Expand its subfolder (name is in current timestamp yyyymmdd_hhmmss), until you see file ResultSummary.trs.  Double click to open this file. You need to install Eclipse BIRT to view the Test Result Statistics Chart. You can also go through every individual report by clicking the leaf node of the result tree and navigating to the corresponding source file.

Eunit005.JPG

  • Tips

You can also select one or more packages, egl files (they must be the same type) to generate the test driver, instead of the entire EGL project.

  • JavaScript

1. Right click on the project you just created, and choose Generate EGL Test Driver > JavaScript to create the JavaScript test driver.

2. There are two ways to execute the test:

  • Go to project eunit.test.eunit.javascript > EGLSource > eunitgen.RunAllTests_rui.egl, open it in EGL Rich UI editor's preview pane, and execute it
  • Go to project eunit.test.eunit.javascript > EGLSource > deploy eunit_test_eunit_javascript.egldd file to a target project. Start the server and then run the html file in the browser.

3. Refresh project eunit.test.eunit.javascript.  You should see a new folder, ResultRoot,.  Then do the same steps as described in the Java section above.