Skip to content

Commit b89030b

Browse files
author
yennj12
committedJan 7, 2025
add
1 parent 1ae4754 commit b89030b

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed
 

‎mobly/README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ python3 hello_world_test_2.py -c sample_config_2.yml --test_bed AbcTestBed
7272
# TEST 3
7373
#-----------------------
7474

75-
7675
python3 sample_test.py -c sample_config_3.yml
7776

7877

78+
#-----------------------
79+
# TEST 4
80+
#-----------------------
81+
82+
python3 many_greetings_test.py -c sample_config.yml
83+
7984

8085
#-----------------------
8186
# TEST 2

‎mobly/many_greetings_test.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from mobly import base_test
2+
from mobly import test_runner
3+
from mobly.controllers import android_device
4+
5+
6+
class ManyGreetingsTest(base_test.BaseTestClass):
7+
8+
# When a test run starts, Mobly calls this function to figure out what
9+
# tests need to be generated. So you need to specify what tests to generate
10+
# in this function.
11+
def pre_run(self):
12+
messages = [('Hello', 'World'), ('Aloha', 'Obama'),
13+
('konichiwa', 'Satoshi')]
14+
# Call `generate_tests` function to specify the tests to generate. This
15+
# function can only be called within `pre_run`. You could
16+
# call this function multiple times to generate multiple groups of
17+
# tests.
18+
self.generate_tests(
19+
# Specify the function that has the common logic shared by these
20+
# generated tests.
21+
test_logic=self.make_toast_logic,
22+
# Specify a function that creates the name of each test.
23+
name_func=self.make_toast_name_function,
24+
# A list of tuples, where each tuple is a set of arguments to be
25+
# passed to the test logic and name function.
26+
arg_sets=messages)
27+
28+
def setup_class(self):
29+
self.ads = self.register_controller(android_device)
30+
self.dut = self.ads[0]
31+
self.dut.load_snippet('mbs', android_device.MBS_PACKAGE)
32+
33+
# The common logic shared by a group of generated tests.
34+
def make_toast_logic(self, greeting, name):
35+
self.dut.mbs.makeToast('%s, %s!' % (greeting, name))
36+
37+
# The function that generates the names of each test case based on each
38+
# argument set. The name function should have the same signature as the
39+
# actual test logic function.
40+
def make_toast_name_function(self, greeting, name):
41+
return 'test_greeting_say_%s_to_%s' % (greeting, name)
42+
43+
44+
if __name__ == '__main__':
45+
test_runner.main()

‎mobly/sample_config_3.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ TestBeds:
22
- Name: TwoDeviceTestBed
33
Controllers:
44
AndroidDevice:
5-
- serial: xyz
6-
label: target
75
- serial: abc
6+
label: target
7+
- serial: def
88
label: discoverer
99
TestParams:
1010
bluetooth_name: MagicBluetooth

0 commit comments

Comments
 (0)