Skip to content

Commit d6676b6

Browse files
committed
Minor improvements of testing documentation
- Fixed instructions for running tests. The mentioned example test had been refactored so the given commands were not able to locate a test to run. - Fixed copy/paste errors in test comments - Documented how to write server-based tests Signed-off-by: Philipp Hasper <[email protected]>
1 parent 176577a commit d6676b6

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CONTRIBUTING.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
234246
We use [shot](https://github.com/Karumi/Shot) for taking screenshots and compare them

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ If you want to [contribute](https://nextcloud.com/contribute/) to the Nextcloud
4848
* reporting problems / suggesting enhancements by [opening new issues](https://github.com/nextcloud/android/issues/new/choose)
4949
* implementing proposed bug fixes and enhancement ideas by submitting PRs (associated with a corresponding issue preferably)
5050
* reviewing [pull requests](https://github.com/nextcloud/android/pulls) and providing feedback on code, implementation, and functionality
51+
* Add [automated tests](CONTRIBUTING.md#testing) for existing functionality
5152
* installing and testing [pull request builds](https://github.com/nextcloud/android/pulls), [daily/dev builds](https://github.com/nextcloud/android#development-version-hammer), or [RCs/release candidate builds](https://github.com/nextcloud/android/releases)
5253
* enhancing Admin, User, or Developer [documentation](https://github.com/nextcloud/documentation/)
5354
* hitting hard on the latest stable release by testing fundamental features and evaluating the user experience

app/src/androidTest/java/com/owncloud/android/AbstractOnServerIT.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,16 @@
5353
import static org.junit.Assert.assertTrue;
5454

5555
/**
56-
* Common base for all integration tests.
56+
* Common base for all integration tests requiring a server connection.
57+
* ATTENTION: Deletes ALL files of the test user on the server after each test run.
58+
* So you MUST use a dedicated test user.
59+
*
60+
* Uses server, user and password given as `testInstrumentationRunnerArgument`
61+
* - TEST_SERVER_URL
62+
* - TEST_SERVER_USERNAME
63+
* - TEST_SERVER_PASSWORD
64+
* These are supplied via build.gradle, which takes them from gradle.properties.
65+
* So look in the latter file to set to your own server & test user.
5766
*/
5867
public abstract class AbstractOnServerIT extends AbstractIT {
5968
@BeforeClass

app/src/androidTest/java/com/owncloud/android/DownloadIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import static org.junit.Assert.assertTrue;
3030

3131
/**
32-
* Tests related to file uploads.
32+
* Tests related to file downloads.
3333
*/
3434
public class DownloadIT extends AbstractOnServerIT {
3535
private static final String FOLDER = "/testUpload/";

0 commit comments

Comments
 (0)