Skip to content

End‐To‐End testing

Charlie edited this page Nov 19, 2024 · 2 revisions

Procedure

How to test that our code still passes the end-to-end tests before merging with main. Find below the precise Git commands and Android Studio instructions, as well as explanations on what all this does.

En bref

You will do every next step locally, which means you never need to push, but will sometimes need to commit your changes.

Let feat/my-branch be the name of the branch you are working on, which you want to test against the end-to-end tests. From that finished branch, create a (local) branch, named for example feat/my-branch-e2e and check it out. Merge the test/end-to-end branch into it. You should now have all the code you were working on, plus the end-to-end tests in feat/my-branch-e2e. Run the tests you need. If they pass, you're all good!

If they do not pass: work on feat/my-branch-e2e to fix your code. Do not work on feat/my-branch while you modify feat/my-branch-e2e. Once you've fixed it, commit your changes (don't commit any change to the end-to-end tests). Since it's just a fix, you should be able to do it in only one commit (the fewer commits, the better), but if there are a lot of changes, you might want to do it in multiple commits.

Then, checkout your working branch feat/my-branch and cherry-pick the fix commit(s) you just made. Now you should have your feat/my-branch with the code you worked on, updated with the fix, but not the end-to-end tests. Well done! Don't forget to delete your feat/my-branch-e2e when you don't need it anymore!

Git commands (from terminal)

# Step 1: Create and checkout a new branch from `feat/my-branch`
git checkout -b feat/my-branch-e2e feat/my-branch

# Step 2: Merge end-to-end tests
# while checked out in `feat/my-branch/e2e`
git merge test/end-to-end

# Step 3: Run tests 
# run tests however you need to

# Step 4: Fix issues if tests fail
# Make necessary code changes
git add .  # only if you've not modified the end-to-end test. 
           # If you have, stage your files one by one 
git commit -m "fix: fix issues found during end-to-end testing"

# Step 5: Cherry-pick fixes
git checkout feat/my-branch
git cherry-pick <commit-hash> # if there are multiple commits, you can do: 
                              # git cherry-pick <commit-hash1> <commit-hash2> ... <commit-hashN>

Don't forget to delete your feat/my-branch-e2e when you don't need it anymore!

From Android Studio

Step 1: Create and checkout a new branch from feat/my-branch

Open the Git panel (Alt+9): Git panel Right-click on feat/my-branch > New branch from 'feat/my-branch'. Name it however you want in the dialog that appears, tick the "Checkout branch" option and then click "Create". You should now be checked into the new branch.

Step 2: Merge end-to-end tests

In the Git panel (Alt+9), find the test/end-to-end branch. Right click on it > Merge 'test/end-to-end' into 'feat/my-branch-e2e'.

Step 3: Run tests

Run your tests.

Step 4: Fix issues if tests fail

Still checked into feat/my-branch-e2e, got to the Commits panel (Alt+0): Commit panel Select the changes you want to commit (do not commit changes to the end-to-end files!), write your commit message (for example: "fix: fix issues found during end-to-end testing") and click on "Commit".

Step 5: Cherry-pick fixes

Check out feat/my-branch: in the Git panel, right-click your feat/my-branch > Checkout. In the commits list, click on the fix you just made. If you want to select multiple commits, you can do Ctrl-click. If you are struggling to find your commits, you can filter the view to only show commits from feat/my-branch-e2e. Then click on Cherry-Pick (here, I have selected three commits to cherry-pick): Cherry-picking

Don't forget to delete your feat/my-branch-e2e when you don't need it anymore!

More explanations about what's happening exactly

This part is AI-generated to save me some time.

Create and Checkout a New Branch:

You create a new branch feat/my-branch-e2e from feat/my-branch. This ensures that feat/my-branch-e2e starts with the same codebase as feat/my-branch.

Merge End-to-End Tests:

You merge the test/end-to-end branch into feat/my-branch-e2e. This adds the end-to-end tests to feat/my-branch-e2e without affecting feat/my-branch.

Run Tests:

You run the end-to-end tests on feat/my-branch-e2e. If the tests pass, you can proceed to whatever you needed to do with your feat/my-branch branch.

Fix Issues if Tests Fail:

If the tests fail, you make the necessary fixes on feat/my-branch-e2e. You commit these fixes to feat/my-branch-e2e (ensuring not to commit any changes to the end-to-end tests themselves).

Cherry-Pick Fixes:

You check out feat/my-branch. You cherry-pick the fix commits from feat/my-branch-e2e to feat/my-branch. This ensures that feat/my-branch gets the necessary fixes without including the end-to-end tests.

Result:

feat/my-branch remains clean and only includes the necessary code and fixes. feat/my-branch-e2e is used for testing and fixing issues related to end-to-end tests. The end-to-end tests are not included in feat/my-branch, keeping it focused on the feature development.