Skip to content

Commit 89b0b38

Browse files
committed
[CI] Introduce Backend Tests
1 parent d5bf1b4 commit 89b0b38

5 files changed

Lines changed: 146 additions & 13 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Backend Checks
2+
3+
on:
4+
workflow_dispatch:
5+
6+
pull_request: # TODO: Delete after testing
7+
8+
concurrency:
9+
group: ${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
env:
13+
BUILD_CACHE_AWS_REGION: ${{ secrets.BUILD_CACHE_AWS_REGION }}
14+
BUILD_CACHE_AWS_BUCKET: ${{ secrets.BUILD_CACHE_AWS_BUCKET }}
15+
BUILD_CACHE_AWS_ACCESS_KEY_ID: ${{ secrets.BUILD_CACHE_AWS_ACCESS_KEY_ID }}
16+
BUILD_CACHE_AWS_SECRET_KEY: ${{ secrets.BUILD_CACHE_AWS_SECRET_KEY }}
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
19+
jobs:
20+
test-backend-integration:
21+
name: Test Backend Integration
22+
runs-on: ubuntu-24.04
23+
env:
24+
ANDROID_API_LEVEL: 34
25+
steps:
26+
- uses: actions/checkout@v4.2.2
27+
- uses: actions/download-artifact@v4.1.8
28+
continue-on-error: true
29+
with:
30+
name: apks
31+
- uses: GetStream/android-ci-actions/actions/setup-java@main
32+
- uses: GetStream/android-ci-actions/actions/enable-kvm@main
33+
- uses: GetStream/android-ci-actions/actions/setup-ruby@main
34+
- name: Run tests
35+
uses: reactivecircus/android-emulator-runner@v2
36+
timeout-minutes: 45
37+
with:
38+
api-level: ${{ env.ANDROID_API_LEVEL }}
39+
disable-animations: true
40+
profile: pixel
41+
arch : x86_64
42+
emulator-options: -no-snapshot-save -no-window -no-audio -no-boot-anim -gpu swiftshader_indirect -camera-back none -camera-front none
43+
script: bundle exec fastlane build_and_run_e2e_test use_backend:true
44+
- name: Upload test results
45+
uses: actions/upload-artifact@v4.4.3
46+
if: failure()
47+
with:
48+
name: logs_${{ env.ANDROID_API_LEVEL }}
49+
path: fastlane/stream-chat-test-mock-server/logs/*

fastlane/Fastfile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ lane :build_and_run_e2e_test do |options|
6565
batch: options[:batch],
6666
batch_count: options[:batch_count],
6767
local_server: options[:local_server],
68-
mock_server_branch: options[:mock_server_branch]
68+
mock_server_branch: options[:mock_server_branch],
69+
use_backend: options[:use_backend]
6970
)
7071
end
7172

@@ -102,16 +103,24 @@ lane :run_e2e_test do |options|
102103
orchestrator_package_name = 'androidx.test.orchestrator/.AndroidTestOrchestrator'
103104
androidx_test_services_path = sh('adb shell pm path androidx.test.services').strip
104105

105-
run_tests_in_batches = batch_tests(
106-
batch: options[:batch],
107-
batch_count: options[:batch_count],
108-
test_apk_path: stream_test_path
109-
)
106+
backend_test_class = 'io.getstream.chat.android.compose.tests.BackendTests'
107+
108+
if options[:use_backend]
109+
test_filter = "-e class #{backend_test_class}"
110+
else
111+
run_tests_in_batches = batch_tests(
112+
batch: options[:batch],
113+
batch_count: options[:batch_count],
114+
test_apk_path: stream_test_path
115+
)
116+
exclude_backend = "-e notClass #{backend_test_class}"
117+
test_filter = run_tests_in_batches.empty? ? exclude_backend : "#{run_tests_in_batches} #{exclude_backend}"
118+
end
110119

111120
result = sh(
112121
"adb shell 'CLASSPATH=#{androidx_test_services_path}' " \
113122
'app_process / androidx.test.services.shellexecutor.ShellMain am instrument -w -e clearPackageData true ' \
114-
"-e targetInstrumentation #{test_package_name}/#{runner_package_name} #{run_tests_in_batches} #{orchestrator_package_name}"
123+
"-e targetInstrumentation #{test_package_name}/#{runner_package_name} #{test_filter} #{orchestrator_package_name}"
115124
)
116125

117126
sh("adb exec-out sh -c 'cd #{adb_test_results_path} && tar cf - #{allure_results_path}' | tar xvf - -C .") if is_ci

stream-chat-android-compose-sample/src/androidTestE2eDebug/kotlin/io/getstream/chat/android/compose/robots/UserRobot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class UserRobot {
117117
fun deleteMessage(messageCellIndex: Int = 0, hard: Boolean = false): UserRobot {
118118
openContextMenu(messageCellIndex)
119119
ContextMenu.delete.waitToAppear().click()
120-
ContextMenu.ok.findObject().click()
120+
ContextMenu.ok.waitToAppear().click()
121121
return this
122122
}
123123

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.getstream.chat.android.compose.tests
2+
3+
import io.getstream.chat.android.compose.robots.assertDeletedMessage
4+
import io.getstream.chat.android.compose.robots.assertMessage
5+
import io.getstream.chat.android.compose.robots.assertMessageAuthor
6+
import io.getstream.chat.android.compose.robots.assertReaction
7+
import io.getstream.chat.android.compose.sample.ui.InitTestActivity
8+
import io.getstream.chat.android.e2e.test.mockserver.ReactionType
9+
import io.qameta.allure.kotlin.Allure.step
10+
import org.junit.Test
11+
12+
class BackendTests : StreamTestCase() {
13+
14+
override var useMockServer = false
15+
override fun initTestActivity() = InitTestActivity.UserLogin
16+
17+
@Test
18+
fun test_message() {
19+
val originalMessage = "hi"
20+
val editedMessage = "hello"
21+
22+
step("GIVEN user opens a channel") {
23+
userRobot.login().openChannel()
24+
}
25+
step("WHEN user sends a message") {
26+
userRobot.sendMessage(originalMessage)
27+
}
28+
step("THEN message appears") {
29+
userRobot.assertMessage(originalMessage)
30+
}
31+
step("WHEN user edits the message") {
32+
userRobot.editMessage(editedMessage)
33+
}
34+
step("THEN the message is edited") {
35+
userRobot.assertMessage(editedMessage)
36+
}
37+
step("WHEN user deletes the message") {
38+
userRobot.deleteMessage()
39+
}
40+
step("THEN the message is deleted") {
41+
userRobot.assertDeletedMessage()
42+
}
43+
}
44+
45+
@Test
46+
fun test_reaction() {
47+
val message = "test"
48+
49+
step("GIVEN user opens the channel") {
50+
userRobot.login().openChannel()
51+
}
52+
step("WHEN user sends the message") {
53+
userRobot.sendMessage(message)
54+
}
55+
step("AND user adds the reaction") {
56+
userRobot.addReaction(type = ReactionType.LIKE)
57+
}
58+
step("THEN the reaction is added") {
59+
userRobot.assertReaction(type = ReactionType.LIKE, isDisplayed = true)
60+
}
61+
step("WHEN user removes the reaction") {
62+
userRobot.deleteReaction(type = ReactionType.LIKE)
63+
}
64+
step("THEN the reaction is removed") {
65+
userRobot.assertReaction(type = ReactionType.LIKE, isDisplayed = false)
66+
}
67+
}
68+
}

stream-chat-android-compose-sample/src/androidTestE2eDebug/kotlin/io/getstream/chat/android/compose/tests/StreamTestCase.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import org.junit.rules.TestName
4141
abstract class StreamTestCase {
4242

4343
lateinit var mockServer: MockServer
44+
open var useMockServer = true
4445
val userRobot = UserRobot()
4546
lateinit var backendRobot: BackendRobot
4647
lateinit var participantRobot: ParticipantRobot
@@ -53,16 +54,20 @@ abstract class StreamTestCase {
5354

5455
@Before
5556
fun setUp() {
56-
mockServer = MockServer(testName.methodName)
57-
backendRobot = BackendRobot(mockServer)
58-
participantRobot = ParticipantRobot(mockServer)
57+
if (useMockServer) {
58+
mockServer = MockServer(testName.methodName)
59+
backendRobot = BackendRobot(mockServer)
60+
participantRobot = ParticipantRobot(mockServer)
61+
}
5962
startApp()
6063
grantAppPermissions()
6164
}
6265

6366
@After
6467
fun tearDown() {
65-
mockServer.stop()
68+
if (useMockServer) {
69+
mockServer.stop()
70+
}
6671
}
6772

6873
@SuppressLint("InlinedApi")
@@ -84,8 +89,10 @@ abstract class StreamTestCase {
8489
private fun startApp() {
8590
testContext.packageManager.getLaunchIntentForPackage(packageName)?.let {
8691
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
87-
it.putExtra("BASE_URL", mockServer.url)
8892
it.putExtra("InitTestActivity", initTestActivity())
93+
if (useMockServer) {
94+
it.putExtra("BASE_URL", mockServer.url)
95+
}
8996
testContext.startActivity(it)
9097
} ?: throw IllegalStateException("No launch intent found for package: $packageName")
9198
}

0 commit comments

Comments
 (0)