Debug Application
When this application is installed, press F12 key to bring the debug window at any time.
The debug applications have two modules:
- Debug window: one can write and run any code snippet directory in the debug window.
- Press F12 key to open it. Or one can open it from the help menu.
- Test Console Window: one can write and run unit test files from a GUI interface.
- Please see UnitTest for more information. One can open the test console from the help menu
Summary of Contents
Debug Window
Copy and paste
NPL script code to the debug window and click run. Each time a script code runs,
it will be saved to a file so that the debugger will automatically reload the last script code.
One can also save script code to files, the first line of the script code is used as the file name.
So it is letter to write debug code as this
-- some description
CallActualCode();
Debug Window is useful for casual unit testing as well. For serious unit testing with automatic result and wiki documentation generation,
please use the Test Console window
Test Console Window
Test Console Window is a GUI front end for the unit test framework in
NPL.
Unit Test Module
The unit test module parses a test file, optionally replace test case input with user supplied ones, and finally output the test result to file and log.
Test file markup:
A test file may contain a group of test cases. Test cases can be declared in
NPL comment block with the following format:
%TESTCASE{"<test_case_name>", func = "<test_function>", input = <default_input>, output="<result_file>"}%
The content inside TESTCASE is actually an
NPL table, where
- test_case_name is test case name, test_function is the name of the function to be called for the test case.
- The test function is usually defined in the test file itself and should use global name.
- default_input is input to the test case function.
- result_file is where to save the test result. if this is nil, it will be saved to testfile.result
For an example test file, please see script/ide/UnitTest/sample_test_file.lua.
--[[
Title: Unit Test sample file
Author(s): LiXizhi
Date: 2008/3/5
Desc:
use the lib:
------------------------------------------------------------
NPL.load("(gl)script/ide/UnitTest/sample_test_file.lua");
test.Example_Test_Function()
-- result at temp/test_result.txt
%TESTCASE{"Example Test", func="test.Example_Test_Function", input={varInt = 1,
varString = "this is a string"}, output="temp/test_result.txt"}%
-- result at script/ide/UnitTest/sample_test_file.lua.result
%TESTCASE{"Example Test 2", func="test.Example_Test_Function", input={varInt2 = 2,
varString2 = "Another input"}}%
-------------------------------------------------------
]]
if(not test) then test ={} end
-- passed by LiXizhi 2008.3.5
function test.Example_Test_Function(input)
log(commonlib.serialize(input).." Test Succeed\n")
end
The result of "Example Test" will be saved to "temp/test_result.txt". It is in TWiki format which one can post to twiki topic.
---+++ case 1
_case_: Example Test
Input:
<verbatim>
{
["varString"] = "this is a string",
["varInt"] = 1,
}
</verbatim>
_Result_:
<verbatim>
{
["varString"] = "this is a string",
["varInt"] = 1,
}
Test Succeed
</verbatim>

To invoke unit test programmatically, use following code
-------------------------------------------------------
NPL.load("(gl)script/ide/UnitTest/unit_test.lua");
local test = commonlib.UnitTest:new();
if(test:ParseFile("script/ide/UnitTest/sample_test_file.lua")) then
test:Run();
end
-- or one can call individually with user input.
local test = commonlib.UnitTest:new();
if(test:ParseFile("script/ide/UnitTest/sample_test_file.lua")) then
test:ClearResult();
local i, count = 1, test:GetTestCaseCount()
for i = 1, count do
test:RunTestCase(i, {"any user input"});
end
end
-------------------------------------------------------

To invoke unit test from a graphically user interface, please install the
DeveloperApp.
Alternatively, one can integrate unit testing UI in any place by calling unit_test_dlg.lua.
- TestConsole? : It can be opened by selecting Menu->Help->TestConsole
Screenshots & User Guide
Detailed Documentation
Installation Instructions
Note: You do not need to install anything on the client to use this contrib package.
- Download the ZIP file from the app web (see below)
- Restart application
Application Info
Related Topics: InsidePE
--
TWiki:Main/LiXizhi - 09 Mar 2008