f2181aa5430ac6d6c3ccb80dbc8ac479e7254995
[AGL/documentation.git] / docs / 4_APIs_and_Services / 4.4_AGL_Test_Framework / 5_Reference / 3_TestFrameworkFunctions / 3_TestFrameworkFunctions.md
1 ---
2 edit_link: ''
3 title: Test Framework Functions
4 origin_url: >-
5   https://git.automotivelinux.org/apps/app-afb-test/plain/docs/Reference/2_TestFrameworkFunctions.md?h=master
6 ---
7
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/apis_services/master/app-afb-test-developer-guides-api-services-book.yml -->
9
10 # Test Framework functions
11
12 * **_AFT.addEventToMonitor(eventName, callback)**
13
14     Add a binding event in the test framework to be able to assert its reception
15     . You'll need to add as much as events you expect to receive. You could also
16     specify a callback to test deeper that the event is as you want to. The
17     callback will happens after the assertion that it has been received so you
18     can work on data that the event eventually carry.
19
20 * **_AFT.setJunitFile(filePath)**
21
22     Set the *JUnit* file path. When *JUnit* is set as the output type for the
23     test framework.
24
25 * **_AFT.setBeforeEach(function)**
26
27     Set the **_AFT.beforeEach()** function which is used to run the *function*
28     before each tests.
29
30 * **_AFT.setAfterEach(function)**
31
32     Set the **_AFT.afterEach()** function which is used to run the *function*
33     after each tests.
34
35 * **_AFT.setBeforeAll(function)**
36
37     Set the **_AFT.beforeAll()** function which is used to run the *function*
38     before all tests. If the given function is successful it has to return 0
39     else it will return an error.
40
41 * **_AFT.setAfterAll(function)**
42
43     Set the **_AFT.afterAll()** function which is used to run the *function*
44     after all tests. If the given function is successful it has to return 0
45     else it will return an error.
46
47 * **_AFT.describe(testName, testFunction, setUp, tearDown)**
48
49     Give a context to a custom test. *testFunction* will be given the name
50     provided by *testName* and will be tested.
51
52     *setUp* and *tearDown* are functions that can be added to your context,
53     it works just like  **_AFT.beforeEach()** and **_AFT.afterEach()**,
54     *setUp* will be ran before your *testFunction* and **_AFT.beforeEach()**
55     (if set) functions, *tearDown* will be ran after your *testFunction* and
56     **_AFT.afterEach()**  (if set) functions.
57
58 * **_AFT.setBefore(testName, beforeTestFunction)**
59
60     Set a function to be ran at the beginning of the given *testName* function.
61
62 ```lua
63     _AFT.testVerbStatusSuccess('testPingSuccess','hello', 'ping', {})
64     _AFT.setBefore("testPingSuccess",function() print("~~~~~ Begin testPingSuccess ~~~~~") end)
65     _AFT.setAfter("testPingSuccess",function() print("~~~~~ End testPingSuccess ~~~~~") end)
66 ```
67
68 * **_AFT.setBefore(testName, beforeTestFunction)**
69
70     Set a function to be ran at the end of the given *testName* function.