Skip to content

Commit

Permalink
Fix #5214, Fix Part of #1723 : Fix onboarding issue faced by new cont…
Browse files Browse the repository at this point in the history
…ributors (#5210)

<!-- READ ME FIRST: Please fill in the explanation section below and
check off every point from the Essential Checklist! -->
## Explanation
Fix #5214 : Wiki link not redirect to correct destination (
good-first-issue link)
Fix Part of #1723 : Fix onboarding issue faced by new contributors.

1. Tell contributors firmly to use "Android Studio Bumblebee | 2021.1.1
Patch 3."
2. In the wiki, make sure to mention that you need to have JDK 11 to use
oppia-android.
3. Concentrate on using robolectric instead of espresso and provide
clear instructions for setting up tests.


<!--
- Explain what your PR does. If this PR fixes an existing bug, please
include
- "Fixes #bugnum:" in the explanation so that GitHub can auto-close the
issue
  - when this PR is merged.
  -->

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [ ] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).
  • Loading branch information
MohitGupta121 authored Oct 31, 2023
1 parent f496e0e commit 094d4a3
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 26 deletions.
62 changes: 47 additions & 15 deletions wiki/Installing-Oppia-Android.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,29 @@ This wiki page explains how to install Oppia Android on your local machine. If y
- [Install oppia-android](#install-oppia-android)
- [Run the app from Android Studio](#run-the-app-from-android-studio)
- [Run the tests](#set-up-and-run-tests)
- [Step-by-Step guidance for setting up and running app modules robolectric test](#step-by-step-guidance-for-setting-up-and-running-app-modules-robolectric-test)
- [For tests that are in non-app modules, such as **domain** or **utility**:](#for-tests-that-are-in-non-app-modules-such-as-domain-or-utility)


## Prepare developer environment

1. Download/Install [Android Studio](https://developer.android.com/studio/?gclid=EAIaIQobChMI8fX3n5Lb6AIVmH8rCh24JQsxEAAYASAAEgL4L_D_BwE&gclsrc=aw.ds#downloads).
1. Download/Install [Android Studio Bumblebee | Patch 3](https://developer.android.com/studio/archive).

**Note**: We recommend installing **Android Studio Bumblebee** because newer versions of Android Studio[ do not support running tests where shared source sets are used](https://issuetracker.google.com/issues/232007221#comment18), a configuration we use at Oppia.
**Note**: We recommend installing **Android Studio Bumblebee | 2021.1.1 Patch 3** because newer versions of Android Studio[ do not support running tests where shared source sets are used](https://issuetracker.google.com/issues/232007221#comment18), a configuration we use at Oppia.

**Direct download Url**: [Windows](https://redirector.gvt1.com/edgedl/android/studio/install/2021.1.1.23/android-studio-2021.1.1.23-windows.exe) | [Linux](https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2021.1.1.23/android-studio-2021.1.1.23-linux.tar.gz) | [Intel Mac](https://redirector.gvt1.com/edgedl/android/studio/install/2021.1.1.23/android-studio-2021.1.1.23-mac.dmg) | [Apple Silicon Mac](https://redirector.gvt1.com/edgedl/android/studio/install/2021.1.1.23/android-studio-2021.1.1.23-mac_arm.dmg)

You can have multiple versions of Android Studio installed on your machine at the same time.

2. Configure your Android Studio
- In Android Studio, open Tools > SDK Manager.
- In the "SDK Platforms" tab (which is the default), select `API Level 28` and also `API Level 31` (for Bazel support).
- In the "SDK Platforms" tab (which is the default), select `API Level 28` and also `API Level 30` (for Bazel support).
- Also, navigate to the "SDK Tools" tab, click the "Show Package Details" checkbox at the bottom right, then click on "Android SDK Build-Tools 34-rc1" and select 29.0.2 (this is needed for Bazel support).

- Then, click "Apply" to download and install these two SDKs/Tools.

- Must have **JDK 11** selected:
- In Android Studio, open Settings > Build, Execution, Deployment > Build Tools > Gradle and edit the Gradle JDK field.

## Install oppia-android

Expand Down Expand Up @@ -81,38 +86,65 @@ Please follow these steps to set up Oppia Android on your local machine.
## Set up and run tests
Testing the app is an integral part of our development process. You will need to test all code changes to ensure that the app works correctly, therefore it is important to ensure that your test configuration works.

We run tests in either Espresso(`app` module tests) or Robolectric(non-app module tests), meaning tests will run in either the emulator or on Gradle/Bazel via the terminal.
We strongly recommend running tests on Robolectric which is faster because it does not require a physical device or emulator setup.

### Configure Robolectric Tests

#### Step-by-Step guidance for setting up and running app modules robolectric test:

1. Go to **Edit Configuration** in Android Studio (Bumblebee | 2021.1.1 Patch 3)
![](https://user-images.githubusercontent.com/9396084/79109714-83525980-7d96-11ea-99d7-f83ea81a8a50.png)

2. Click on Add(+) -> **JUnit**
![](https://github.com/oppia/oppia-android/assets/76530270/87caf3fc-37d9-472d-92fd-b8ec49fb6b49)

3. Enter following information:
- a) Name of test. Example: In my case "SplashActivityTest"
- b) Make sure select "java 11" and oppia-android.app
- c) Class path of Test class. Example: In my case "org.oppia.android.app.splash.
SplashActivityTest"
- d) Press `OK` to select the test.
![](https://github.com/oppia/oppia-android/assets/76530270/5901624a-df76-4b27-8f31-6077a68fcb89)

4. Click on "Run" button to run robolectric test. (In my case "SplashActivityTest")
![](https://github.com/oppia/oppia-android/assets/76530270/75a6b998-90c5-4f0a-8886-78f96970be90)

#### For tests that are in non-app modules, such as **domain** or **utility**::

1. In Android Studio, open the desired test file, e.g., `AnalyticsControllerTest`.
2. In the test file, to the left of the class name, click on the orange and green arrow, and select **Run 'AnalyticsControllerTest'**.
- You will notice that the emulator is greyed out, but the run window will open to show the running tests:
![](https://user-images.githubusercontent.com/59600948/272657015-158117e5-47d2-40fc-a38b-5dee6c347556.png)

### Configure Emulator Tests

**Espresso is slower for running tests, so we recommend using Robolectric.**

1. In Android Studio, open the desired test file, e.g., `HomeActivityTest`.
2. In the Android Studio toolbar, click on the `Available Devices` option. Select an emulator that has between API 28-30.

**Note**: If you don't have any available devices in this list, please follow [these instructions](#run-the-app-from-android-studio) to create one.

3. In the test file, to the left of the class name, click on the orange and green arrow, and select **Run 'HomeActivityTest'**.
![](https://user-images.githubusercontent.com/59600948/272657131-96e5354b-13a9-4709-969a-b9494a65c30f.png)
![](https://user-images.githubusercontent.com/59600948/272657131-96e5354b-13a9-4709-969a-b9494a65c30f.png)

4. An "**Edit Configuration**" dialog will show up, and you should add the following settings under the general tab:
- For module, select **oppia-android.app**
- For Test, select **Class**
- For Instrumentation class, **org.oppia.android.testing.OppiaTestRunner**, will be selected by default.
- For target, select the **Use the device/snapshot dropdown** option.
- Verify that your setup looks like below:
-![](https://user-images.githubusercontent.com/59600948/272657260-2e654891-61be-467a-8ebd-c997aa2abda6.png)

![](https://user-images.githubusercontent.com/59600948/272657260-2e654891-61be-467a-8ebd-c997aa2abda6.png)
- Finally, Click the "Apply" and "Okay" buttons.
- You may need to repeat step (3) above to run the test with the new configuration.
- Subsequent runs of any app module tests will not require editing the configuration.
- This configuration will run all the tests in that class.
5. To run only a specific test in a file:
- Search or scroll down to the desired test name, to the left of the test name, click on the run icon and select **Run '`test name`''**.

### Configure Robolectric Tests
These are tests that are in non-app modules, such as **domain** or **utility**.
1. In Android Studio, open the desired test file, e.g., `AnalyticsControllerTest`.
2. In the test file, to the left of the class name, click on the orange and green arrow, and select **Run 'AnalyticsControllerTest'**.
- You will notice that the emulator is greyed out, but the run window will open to show the running tests:
- ![](https://user-images.githubusercontent.com/59600948/272657015-158117e5-47d2-40fc-a38b-5dee6c347556.png)


### Next Steps
- Congratulations, you are ready to work on your first issue! Take a look at our [good first issues](https://github.com/oppia/oppia-android/wiki/Oppia-Android-Testing) and leave a comment with your suggested fix. A maintainer will assign you the issue and provide any necessary guidance.
- Congratulations, you are ready to work on your first issue! Take a look at our [good first issues](https://github.com/oppia/oppia-android/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22+no%3Aassignee) and leave a comment with your suggested fix. A maintainer will assign you the issue and provide any necessary guidance.

- When you are ready to submit a PR, please follow [these instructions](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR) on submitting a PR.

Expand Down
27 changes: 16 additions & 11 deletions wiki/Oppia-Android-Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,22 @@ public class MyActivityTest {
```

### Running Robolectric tests
1. Go to **Edit Configuration** in Android Studio
<img width="425" alt="Screenshot 2020-04-13 at 2 51 02 PM" src="https://user-images.githubusercontent.com/9396084/79109714-83525980-7d96-11ea-99d7-f83ea81a8a50.png">

2. Add **Android JUnit**
<img width="1070" alt="Screenshot 2020-04-13 at 2 51 31 PM" src="https://user-images.githubusercontent.com/9396084/79109717-851c1d00-7d96-11ea-92c1-2e8a9c6ef88f.png">

3. Enter following information - (a.) **Name** (Normally class name) (b.)**Use classpath of module** (c.) **Class**
<img width="1074" alt="Screenshot 2020-04-13 at 3 18 39 PM" src="https://user-images.githubusercontent.com/9396084/79111450-307aa100-7d9a-11ea-8b9d-81aac26e104d.png">


4. Press `OK` to run the test cases in robolectric.
1. Go to **Edit Configuration** in Android Studio (Bumblebee | 2021.1.1 Patch 3)
![](https://user-images.githubusercontent.com/9396084/79109714-83525980-7d96-11ea-99d7-f83ea81a8a50.png)

2. Click on Add(+) -> **JUnit**
![](https://github.com/oppia/oppia-android/assets/76530270/87caf3fc-37d9-472d-92fd-b8ec49fb6b49)

3. Enter following information:
- a) Name of test. Example: In my case "SplashActivityTest"
- b) Make sure select "java 11" and oppia-android.app [**Note:** For "app module test" select `oppia-android.app` similarly for "utility tests" select `oppia-android.utility`, for "domain test" select `oppia-android.domain`, for "model test" select `oppia-android.model`, for "testing" select `oppia-android.testing`]
- c) Class path of Test class. Example: In my case "org.oppia.android.app.splash.
SplashActivityTest"
- d) Press `OK` to select the test.
![](https://github.com/oppia/oppia-android/assets/76530270/5901624a-df76-4b27-8f31-6077a68fcb89)

4. Click on "Run" button to run robolectric test. (In my case "SplashActivityTest")
![](https://github.com/oppia/oppia-android/assets/76530270/75a6b998-90c5-4f0a-8886-78f96970be90)

## Espresso

Expand Down

0 comments on commit 094d4a3

Please sign in to comment.