Auto-tools/Projects/Robocop/WritingTests: Difference between revisions

Line 26: Line 26:


Each test class must have three methods:  
Each test class must have three methods:  
<pre>
protected void setUp() // Starts Fennec and sets up commonly used member variables. This is usually very similar for every test class.
protected void setUp() // Starts Fennec and sets up commonly used member variables. This is usually very similar for every test class.
public void test[YourFeature]() // Your test code goes here. Use the Robocop API to access Fennec elements, click, send keys, and assert conditions.
public void test[YourFeature]() // Your test code goes here. Use the Robocop API to access Fennec elements, click, send keys, and assert conditions.
Line 35: Line 34:


Finally, add your new test file to the test manifest: mobile/android/base/tests/robocop.ini.
Finally, add your new test file to the test manifest: mobile/android/base/tests/robocop.ini.
== Creating a new Content Provider test ==
We have infrastructure for testing content providers in an isolated environment. This means that we ensure that any updates to the databases behind content providers will not affect or be affected by the Fennec app.
To write a content provider test, you should follow the same file naming and Java packaging guidelines described for UI tests. However, you should create a class that inherits from ''ContentProviderTest'' instead of ''BaseTest'' or ''ActivityInstrumentationTestCase2''. Each Content Provider test class must have those the same three methods than UI tests (setUp(), test[YourFeature]() and tearDown) with one important difference: the ''setUp()'' method should call the following parent method:
<pre>
protected void setUp(String className, String authorityField);
</pre>
Where ''className'' is the class of your content provider and ''authorityField'' is the name of the property in ''BrowserContract'' containing your content provider AUTHORITY string. For example, for BrowserProvider, the ''setUp()'' method would look something like:
<pre>
public setUp() throws Exception {
    super.setUp("@ANDROID_PACKAGE_NAME@.db.BrowserProvider", "AUTHORITY");
    // Then other setup operations...
}
</pre>
After this is called, ''mProvider'' will point to your an isolated instance of your content provider and you can make insert/query/update/delete calls on it as expected. For more details and sample code on how to implement Content Provider tests, have a look at the testBrowserProvider.java.in.


= APIs  =
= APIs  =
Confirmed users
251

edits