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 ()
0 commit comments