我的之前一篇文章讲解了如何在 Linux 下编译 LibreOffice。编译完成后,您可以手动运行它,测试一些常见的功能看看是不是能正常工作。但是,手动运行太慢了,而且不能涵盖所有的操作和功能。这时候,“单元测试” (Unit Test) 就很有用了。
单元测试可以自动运行在源代码中预先定义好的操作(即测试用例,Test Case),若某个测试用例运行失败,会给出错误提示。在新版本发布之前,或者在某个commit被正式提交到代码树中时,一般均会在多个平台上完整运行这些单元测试。但是,这并不意味着万事大吉,别人运行单元测试通过了,并不代表在你的机器上也能通过。如果在你的机器上运行不通过,那么很可能出现了与特定平台相关的 bug。
据我了解,LibreOffice的单元测试有两类:一类是c++写的用于测试底层功能逻辑的,叫 cpp unit test, 涵盖范围很广。另一类是用 Python 写的用于测试用户界面基本功能的,叫 UI Test,这一类单元测试目前涵盖的范围很有限,是近几年才在逐渐完善的,基本上每个与用户界面相关的bug被修复之后就会有人创建一个 UI Test 测试用例,从而确保同样的 bug 在后续版本中不会再出现。
编译完 LibreOffice 之后,要运行 UI Test,只需要使用以下命令:
make UITest
测试命令行界面给出如下运行结果,表明这些测试均通过了:
$ make UITest
make -j 4 -rs -f <path>/Makefile.gbuild UITest
[PRL] CustomTarget/postprocess/images/commandimagelist.ilst
[PRL] CustomTarget/helpcontent2/source/auxiliary/helpimg.ilst
...
[MOD] postprocess
[ALL] All modules but instset: UnoControls accessibility animations ... xmlsecurity
[UIT] cui_dialogs
[UIT] conditional_format
[UIT] range_name
[UIT] hide_cols
[UIT] autofilter
[UIT] search_replace
[UIT] calc_tests
[UIT] calc_tests2
[UIT] calc_tests3
[UIT] calc_tests4
[UIT] calc_tests6
[UIT] statistics
[UIT] solver
[UIT] goalSeek
[UIT] protect
[UIT] sc_options
[UIT] validity
[UIT] key_f4
[UIT] textCase
[UIT] signatureLine
[UIT] inputLine
[UIT] calc_tests7
[UIT] sort
[UIT] chart
[UIT] pageFormat
[UIT] calc_tests8
[UIT] calc_dialogs
[UIT] calc_tests9
[UIT] function_wizard
[UIT] manual_tests
[UIT] impress_tests
[UIT] sd_findReplace
[UIT] sfx2_doc
[UIT] svx_table
[UIT] librelogo
[UIT] writer_tests
[UIT] writer_tests2
[UIT] writer_tests3
[UIT] writer_tests4
[UIT] writer_tests5
[UIT] writer_tests6
[UIT] writer_tests7
[UIT] sw_table
[UIT] sw_chart
[UIT] sw_findBar
[UIT] sw_findReplace
[UIT] sw_findSimilarity
[UIT] chapterNumbering
[UIT] sw_navigator
[UIT] sw_options
[UIT] sw_sidebar
[UIT] sw_styleInspector
[UIT] sw_ui_fmtui
[UIT] sw_ui_index
[UIT] classification
[UIT] writer_macro_tests
[UIT] writer_dialogs
[UIT] impress_demo
[UIT] demo_ui
[UIT] math_demo
[UIT] writerperfect_epubexport
但是,也有可能某个测试用例在你的系统上测试不通过,比如我就遇到了一个:
[UIT] sw_chart
False
test_stock_chart13_insert_series (tdf138556.tdf138556) … OfficeConnection: connecting to: uno:pipe,name=pytest822f28f4-bdc7-11eb-9146-0c54153de046;urp;StarOffice.ComponentContext
NoConnectException: sleeping…
['OnNew']
OnCreate
...
OnModeChanged
Execution time for tdf138556.tdf138556.test_stock_chart13_insert_series: 2.263
Binary URP bridge already disposed /home/suokunlong/lo/source/shallow-master-non-dbg/binaryurp/source/bridge.cxx:1047
ERROR
ERROR
======================================================================
ERROR: test_stock_chart13_insert_series (tdf138556.tdf138556)
Traceback (most recent call last):
File "<path>/sw/qa/uitest/chart/tdf138556.py", line 45, in test_stock_chart13_insert_series
xToolbar.executeAction( "CLICK", mkPropertyValues({ "POS" : "1" }))
tdf138556.com.sun.star.lang.DisposedException: Binary URP bridge disposed during call /home/suokunlong/lo/source/shallow-master-non-dbg/binaryurp/source/bridge.cxx:613
这说明 bug 138556 中的问题在我的系统上可能还没解决,但进一步分析发现这是另外一个问题,即在 sw/qa/uitest/chart/tdf138556.py” 的45行操作之前 libreoffice 已经崩溃了,也就是我报告的 bug 142467.
发表回复