From ce384e325a9ed7f64e5e8dd3af78b509fa251935 Mon Sep 17 00:00:00 2001 From: chenhaoran Date: Thu, 16 Jan 2025 17:50:54 +0800 Subject: [PATCH] ci:modify test readme --- tests/README.md | 45 +++++++++++++-- .../0-others/test_case_template.py | 55 +++++++++++++++++++ 2 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 tests/system-test/0-others/test_case_template.py diff --git a/tests/README.md b/tests/README.md index ff42c9bb3d..f684c8977c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -92,28 +92,34 @@ bash test.sh -e 0 #### How to add new cases? +
+ +Detailed steps to add new unit test case + The Google test framwork is used for unit testing to specific function module, you can refer below steps to add one test case: -##### Create test case file and develop the test scripts +##### 1. Create test case file and develop the test scripts In the test directory corresponding to the target function module, create test files in CPP format and write corresponding test cases. -##### Update build configuration +##### 2. Update build configuration Modify the CMakeLists.txt file in this directory to ensure that the new test files are properly included in the compilation process. See the source\os\test\CMakeLists.txt file for configuration examples. -##### Compile test code +##### 3. Compile test code In the root directory of the project, create a compilation directory (e.g., debug), switch to the directory and run CMake commands (e.g., cmake .. -DBUILD_TEST=1) to generate a compilation file, and then run a compilation command (e.g. make) to complete the compilation of the test code. -##### Execute the test program +##### 4. Execute the test program Find the executable file in the compiled directory(e.g. TDengine/debug/build/bin/) and run it. -##### Integrate into CI tests +##### 5. Integrate into CI tests Use the add_test command to add new compiled test cases into CI test collection, ensure that the new added test cases can be run for every build. +
+ ## 3.1.2 System Test Python test script includes all of the functions of TDengine OSS, so some test case maybe fail cause the function only @@ -135,7 +141,34 @@ cd tests ### How to add new case? -[Placeholder] +
+ +Detailed steps to add new system test case + +you can refer below steps to add one test case: + +##### 1. Create test case file and develop the test scripts + +In the test directory corresponding to the target function module, create test files in CPP format and write corresponding test cases. + +##### 2. Update build configuration + +Modify the CMakeLists.txt file in this directory to ensure that the new test files are properly included in the compilation process. See the source\os\test\CMakeLists.txt file for configuration examples. + +##### 3. Compile test code + +In the root directory of the project, create a compilation directory (e.g., debug), switch to the directory and run CMake commands (e.g., cmake .. -DBUILD_TEST=1) to generate a compilation file, and then run a compilation command (e.g. make) to complete the compilation of the test code. + +##### 4. Execute the test program + +Find the executable file in the compiled directory(e.g. TDengine/debug/build/bin/) and run it. + +##### 5. Integrate into CI tests + +Use the add_test command to add new compiled test cases into CI test collection, ensure that the new added test cases can be run for every build. + +
+ ## 3.1.3 Legacy Test diff --git a/tests/system-test/0-others/test_case_template.py b/tests/system-test/0-others/test_case_template.py new file mode 100644 index 0000000000..53acbade66 --- /dev/null +++ b/tests/system-test/0-others/test_case_template.py @@ -0,0 +1,55 @@ + +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes +from util.dnodes import * +from util.common import * + + +class TDTestCase: + + """ + Here is the class description for the whole file cases + """ + + # add the configuration of the client and server here + clientCfgDict = {'debugFlag': 131} + updatecfgDict = { + "debugFlag" : "131", + "queryBufferSize" : 10240, + 'clientCfg' : clientCfgDict + } + + def init(self, conn, logSql, replicaVar=1): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + self.replicaVar = int(replicaVar) + + + def test_function(): # case function should be named start with test_ + """ + Here is the function description for single test: + Test case for custom function + """ + tdLog.info(f"Test case test custom function") + # excute the sql + tdLog.execute(f"create database db_test_function") + tdSql.execute(f"create table db_test_function.stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int unsigned);") + # qury the result and return the result + tdSql.query(f"show databases") + # print result and check the result + database_info = tdLog.info(f"{tdSql.queryResult}") + tdSql.checkRows(3) + tdSql.checkData(2,0,"db_test_function") + + + def run(self): + self.test_5dnode_3mnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='vnode') + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase())