Using RTest to Create Test Harness(use in Symbian OS)

原创 2004年12月29日 12:20:00

This article gives an introduction how to use RTest class to create automatic test harness for your application engines. The RTest class provides a simple console window where you can display the test result. Unfortunately it is not possible to use RTest for GUI testing.

Test harness basically is a black box testing. It calls a function and then compares the result value with a reference value. When the result value is the same with the reference value, the test passes; if they are not the same, then the test fails. RTest will help you to create an automatic test harness; it will display the test result on the screen and panic if one of tests fails.

Using RTest

RTest creates a console window where you can output the test result or check a boolean expression. The expression usually compares a variable or the result of a function call with a reference value.

The RTest class is declared in e32test.h. The following example shows how to use RTest class.

#include <e32test.h>

GLDEF_C TInt E32Main()
   _LIT(KTestTitle, "My Testing");
   RTest iTest(KTestTitle);

   _LIT(KFirstTest, "First Test");

   // Your testing code...



The first two lines in the main program, E32Main(), defines an instance of RTest class and gives the title KTestTitle. You can display the title by calling Title() method, like shown in the second line. At the end of the program, all the resources needed by RTest are freed by calling Close() method.

As you see in this example, before starting the test suite, you have to call Start(); and at the end, you have to call End(). Note that Start() must be ended by End(); do not forget to call End()!

Now let’s start with a very simple test, i.e. to compare a defined integer with a constant. Add the following code between Start() and End().

TInt i = 10;
iTest(i == 10);

The first line defines an integer which has the value of 10. The second line calls the operator RTest::() that compares i with 10. This operator will do nothing if the condition is true; and raise a panic if it is false. Since this simple expression above will always return true; the test program will run without panic. If you run the program, you will see the emulator window like Figure 1a.

Figure 1a  The emulator that shows the test passes - 71.1 kb
Figure 1a The emulator that shows the test passes
Figure 1b The emulator that shows the test fails - 71.4 kb
Figure 1b The emulator that shows the test fails

Next, try to change the condition to the following statement.

iTest(i == 11);

The statement above will return false; thus if you run the program you will get an emulator window like Figure 1b and your program will panic.

More About RTest::()

There are three variants of RTest::() operator. The first variant, as you see above, requires one parameter, that is the expression to be checked.

The second variant has one additional parameter, that is the line number information. In case of failure, the line number will be displayed on the screen. For example:

iTest(expression, 12345);

The third has one more additional parameter, that is the file name that will be printed on the screen when a failure mode occurs. For example:

iTest(expression, 12345, L"Testing.cpp");

When the expression fails, you will notice that the failure is in Testing.cpp file at line number 12345.

Test Numbering

When your test suite contains of several tests, you can add numbering to them by calling Next() for each test. For example, if you have three tests, you can write a program like the example below.

_LIT(KFirstTest, "First Test");
// The first test...

_LIT(KSecondTest, "Second Test");
// The second test...

_LIT(KThirdTest, "Third Test");
// The third test...


The output of the example above can be seen in Figure 2a.

Figure 2a. Test numbering in RTest. - 71.7 kb
Figure 2a. Test numbering in RTest.
Figure 2b  Nested numbering in RTest. - 72.7 kb
Figure 2b Nested numbering in RTest.

You can also have nested numbering by calling Start() inside another Start(). The following example shows how to have nested numbering like shown in Figure 2b.

_LIT(KTest1, "Test 1");
// Test 1

_LIT(KTest11, "Test 1.1");
// Test 1.1

_LIT(KTest12, "Test 1.2");
// Test 1.2

_LIT(KTest121, "Test 1.2.1");
// Test 1.2.1

_LIT(KTest122, "Test 1.2.2");
// Test 1.2.2

_LIT(KTest123, "Test 1.2.3");
// Test 1.2.3

iTest.End(); // Test 1.2

iTest.End(); // Test 1

_LIT(KTest2, "Test 2");
// Test 2


I hope this article will give you an understanding how to create test harness using RTest class. There is another alternative to RTest, called Symbian OS Unit (see the link at the end of this article). It is an open source project, based on JUnit from Java.

Symbian OS 源码下载方式

本文由 撰写,转载请说明。Symbian OS 源码下载方式,导航:近日Symbian OS开源,肯定有很多移动开发爱好者去下载Symbian系统代码。但是笔者发现S...
  • wag2765
  • wag2765
  • 2016年01月25日 16:41
  • 509

Android 压力测试 (记录bug)

Android 压力测试 (记录bug)
  • guang_liang_
  • guang_liang_
  • 2017年04月15日 16:17
  • 472

unity3d - new 不出的单例

可能习惯了写单例的朋友,或者常规的单例模式 会这样做 private static Single instance; public static Single Instance(){ i...
  • pdw_jsp
  • pdw_jsp
  • 2015年11月19日 11:16
  • 3843


iOS远程推送通知服务APNs 苹果的APNs(苹果推送通知服务Apple Push Notification server)允许设备和苹果的推送通知服务器保持链接,支持开发者推送消息到给用户设备对...
  • li_shuang_ls
  • li_shuang_ls
  • 2015年11月05日 19:25
  • 853

Simulink 模块仿真验证

  • j353838430
  • j353838430
  • 2017年03月26日 17:12
  • 495

Spark SQL之External DataSource外部数据源(一)示例

一、Spark SQL External DataSource简介  随着Spark1.2的发布,Spark SQL开始正式支持外部数据源。Spark SQL开放了一系列接入外部数据源的接口,来让开发...
  • u014388509
  • u014388509
  • 2014年12月22日 01:12
  • 7255

关于Mat和using namespace cv的使用理解(一)

参考: 参考文档:OpenCV中Mat的详解 之前一直再用IplImage类型,昨天...
  • xumi13
  • xumi13
  • 2016年10月05日 10:11
  • 6224


____tz_zs 本篇为学习tensorflow为加深对计变量的初始化,张量的计算取值的理解所写的小Demo。因作者水平限制,可能有些片面或错误,欢迎指出,共同进步。 # -*- codin...
  • tz_zs
  • tz_zs
  • 2017年07月31日 21:59
  • 1380

Python·Jupyter Notebook各种使用方法记录·持续更新

Python·Jupyter Notebook各种使用方法记录·持续更新 转载:
  • gx19862005
  • gx19862005
  • 2017年03月03日 16:04
  • 571

python 环境配置总结

  • sqiu_11
  • sqiu_11
  • 2017年01月31日 22:56
  • 1039
您举报文章:Using RTest to Create Test Harness(use in Symbian OS)