@@ -217,18 +217,30 @@ Source code of app:
217217#### Instrumented tests
218218- tests to see larger code working in correct way
219219- tests that require parts of Android SDK
220- - best to avoid server communication, see https://github.com/nextcloud/android/pull/3624
221220
222221- run all tests ``` ./gradlew createGplayDebugCoverageReport -Pcoverage=true ```
223222- run selective test class: ```./gradlew createGplayDebugCoverageReport -Pcoverage=true
224- -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerTest ```
223+ -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerContentProviderClientIT ```
225224- run multiple test classes:
226225 - separate by ","
227- - ``` ./gradlew createGplayDebugCoverageReport -Pcoverage=true -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerTest ,com.nextcloud.client.FileDisplayActivityIT ```
226+ - ``` ./gradlew createGplayDebugCoverageReport -Pcoverage=true -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerContentProviderClientIT ,com.nextcloud.client.FileDisplayActivityIT ```
228227- run one test in class: ```./gradlew createGplayDebugCoverageReport -Pcoverage=true
229- -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerTest#saveNewFile ```
228+ -Pandroid.testInstrumentationRunnerArguments.class=com.owncloud.android.datamodel.FileDataStorageManagerContentProviderClientIT#saveFile ```
230229- JaCoCo results are shown as html: firefox ./build/reports/coverage/gplay/debug/index.html
231230
231+ #### Instrumented tests with server communication
232+ It is best to avoid server communication, see https://github.com/nextcloud/android/pull/3624 .
233+ But if a test requires a server, this is how it is done:
234+ - Have a Nextcloud service reachable by your test device. This can be an existing server in the internet or a locally deployed one
235+ as per the [ server developer documentation] ( https://docs.nextcloud.com/server/latest/developer_manual/getting_started/devenv.html )
236+ - Create a separate(!) test user on that server, otherwise the tests will infer with productive data.
237+ - In ` gradle.properties ` , enter the URL, user name and password via the ` NC_TEST_SERVER_... ` attributes.
238+ If you want to prevent an accidental commit of those, you can also store them in ` ~/.gradle/gradle.properties ` .
239+ - Your test class should inherit from ` AbstractOnServerIT ` , e.g.: ` public class DownloadIT extends AbstractOnServerIT { ... `
240+ Note that this will automatically delete all files after each test run, so you absolutely NEED a separate test user as mentioned above.
241+ - All preconditions of your test regarding server data, e.g. existing files, need to be established by your test itself.
242+ As a reference, see how ` DownloadIT ` first uploads the files it later tests the download with.
243+ - Clean up these preconditions again, also in the failure case, using one or multiple ` @After ` methods in your test class.
232244
233245#### UI tests
234246We use [ shot] ( https://github.com/Karumi/Shot ) for taking screenshots and compare them
0 commit comments