commit | 171092d2b296115510b5bc0b3cf224a4b05fc638 | [log] [tgz] |
---|---|---|
author | Alexander Dorokhine <adorokhine@google.com> | Wed Nov 02 20:36:10 2016 -0700 |
committer | adorokhine <adorokhine@users.noreply.github.com> | Mon Nov 28 14:02:28 2016 -0800 |
tree | 53f80728a219500c8dcf5cb2dec833f9fa368a6b | |
parent | b1b8b500aaba3aff53a38aae783754915b2ee555 [diff] |
Create a builtin help() RPC. Cleans up the RPC description handling and allows removal of a lot of unneeded annotations.
Mobly Snippet Lib is a library for triggering device-side code from host-side Mobly tests. This tutorial teaches you how to use the snippet lib to trigger custom device-side actions.
This is not an official Google product.
Link against Mobly Snippet Lib in your build.gradle
file
apply plugin: 'com.android.application' dependencies { androidTestCompile 'com.google.android.mobly:snippetlib:0.0.1' }
In your androidTest
source tree, write a Java class implementing Snippet
and add methods to trigger the behaviour that you want. Annotate them with @Rpc
package com.my.app.test; ... public class ExampleSnippet implements Snippet { public ExampleSnippet(Context context) {} @Rpc(description='Returns a string containing the given number.') public String getFoo(Integer input) { return 'foo ' + input; } @Override public void shutdown() {} }
Add any classes that implement the Snippet
interface in your AndroidManifest.xml
application section as meta-data
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.my.app.test"> <application> <meta-data android:name="mobly-snippets" android:value="com.my.app.test.MySnippet1, com.my.app.test.MySnippet2" /> ...
Build your apk and install it on your phone
In your Mobly python test, connect to your snippet .apk in setup_class
class HelloWorldTest(base_test.BaseTestClass): def setup_class(self): self.ads = self.register_controller(android_device) self.dut1 = self.ads[0] self.dut1.load_snippets(name='snippet', package='com.my.app.test') if __name__ == '__main__': test_runner.main()
Invoke your needed functionality within your test
def test_get_foo(self): actual_foo = self.dut1.snippet.getFoo(5) asserts.assert_equal("foo 5", actual_foo)