3 created by [Cédric Ollivier](mailto:cedric.ollivier@orange.com)
9 - Functest integrates lots of heterogeneous testcases:
11 - internal vs external
12 - it aims to benefit from object programming
13 - to define common operations
14 - to avoid conditional instructions regarding the testcases
15 - to avoid duplicating code
16 - to ease the integration of third-party testcases (written in Bash or Python)
23 ### Functest function calls
25 - **CI** calls *run_tests.py* (please see [jenkins jobs](https://gerrit.opnfv.org/gerrit/gitweb?p=releng.git;a=tree;f=jjb/functest))
26 - *run_tests.py* parses *functest/ci/testcases.yaml* to:
27 - check which testcase(s) must be run
28 - execute the common operations on every testcase (run, push its results to db...)
29 <!-- .element: class="fragment highlight-red"-->
30 - return the right status code to **CI**
35 - limit run_tests.py instructions by defining:
36 - the basic testcase attributes
37 - all common operations
38 - the status codes expected
39 - avoid duplicating codes between testcases
40 - ease the development of third-party testcases (aka features)
46 base model for single test case
49 ### instance attributes
51 - project_name (default: 'functest')
63 |-------------------|--------------------------------------------|
64 | run(**kwargs) | run the test case |
65 | is_successful() | interpret the results of the test case |
66 | get_duration() | return the duration of the test case |
67 | push_to_db() | push the results of the test case to the DB|
72 - the subclasses must override the default implementation which is false on purpose
73 - the new implementation must set the following attributes to push the results to DB:
81 | Status code | Returned when |
82 |--------------------|---------------------|
83 | EX_OK | everything is OK |
84 | EX_RUN_ERROR | run() failed |
85 | EX_TESTCASE_FAILED | results are false |
86 | EX_PUSH_TO_DB_ERROR| push_to_db() failed |
92 module = importlib.import_module(run_dict['module'])
93 cls = getattr(module, run_dict['class'])
94 test_dict = ft_utils.get_dict_by_test(test_name)
95 test_case = cls(**test_dict)
97 kwargs = run_dict['args']
98 result = test_case.run(**kwargs)
100 result = test_case.run()
101 if result == testcase.TestCase.EX_OK:
102 if GlobalVariables.REPORT_FLAG:
103 test_case.push_to_db()
104 result = test_case.is_successful()
109 ## Your first test case
115 #!/usr/bin/env python
119 from functest.core import testcase
121 class Test(testcase.TestCase):
123 def run(self, **kwargs):
124 self.start_time = time.time()
127 self.stop_time = time.time()
128 return testcase.TestCase.EX_OK
132 ### functest/ci/testcases.yaml
136 project_name: functest
154 base model for single feature
160 |-------------------|---------------------------|
161 | run(**kwargs) | run the feature |
162 | execute(**kwargs) | execute the Python method |
167 - allows executing any Python method by calling execute()
168 - sets the following attributes required to push the results to DB:
172 - doesn't fulfill details when pushing the results to the DB.
175 ### execute(**kwargs)
177 - the subclasses must override the default implementation which is false on purpose
178 - the new implementation must return 0 if success or anything else if failure.
182 ## Your second test case
188 #!/usr/bin/env python
190 from functest.core import feature
192 class Test(feature.Feature):
194 def execute(self, **kwargs):
200 ### functest/ci/testcases.yaml
204 project_name: functest
222 class designed to run any bash command
225 ### execute(**kwargs)
227 execute the cmd passed as arg.
231 ## Your third test case
234 ### functest/ci/testcases.yaml
238 project_name: functest
247 module: 'functest.core.feature'
250 cmd: 'echo Hello World; exit 0'
258 base model for running unittest.TestSuite
263 - allows running any unittest.TestSuite
264 - sets the following attributes required to push the results to DB:
272 ## Your fourth test case
278 #!/usr/bin/env python
282 class TestStringMethods(unittest.TestCase):
284 def test_upper(self):
285 self.assertEqual('Hello World'.upper(),
290 ### functest/ci/testcases.yaml
294 project_name: functest
303 module: 'functest.core.unit'
316 - __to finish VNF abstraction (coverage + pylint)__
318 - to manage criteria as written in testcases.yaml
320 Please see [Functest Euphrates page](https://wiki.opnfv.org/display/functest/Functest+Euphrates+page) for more details