Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

안드로이드 테스트 자동화 #49

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 77 additions & 6 deletions .github/workflows/dev-test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Test
name: Test
on:
pull_request:
branches: [ "dev" ]
Expand All @@ -17,7 +17,7 @@ jobs:
echo "Changed files: ${{ steps.changed_files.outputs.all_changed_files }}"
TEST_FILES=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" \
| tr ' ' '\n' \
| grep -E '^.+/src/test/(java|kotlin)/.+\.(kt|java)$')
| grep -E '^.+/src/test/(java|kotlin)/.+\.(kt|java)$' || true)
echo "Filtered by grep: $TEST_FILES"
TEST_FILES=$(echo "$TEST_FILES" \
| sed -E 's/^(.+)\/src\/test\/(java|kotlin)\/(.+)\.(kt|java)$/\1 \3/' \
Expand All @@ -26,7 +26,7 @@ jobs:
TEST_FILES_SINGLE_LINE=$(echo "$TEST_FILES" | tr '\n' ' ')
echo "TEST_FILES=$TEST_FILES_SINGLE_LINE" >> $GITHUB_ENV
echo "$TEST_FILES" > test_files.txt
if [ -s test_files.txt ]; then
if [ -n "$(cat test_files.txt | xargs)" ]; then
echo "any_changed=true" >> $GITHUB_ENV
else
echo "any_changed=false" >> $GITHUB_ENV
Expand Down Expand Up @@ -58,8 +58,8 @@ jobs:
while IFS=$'\n' read -r LINE; do

# 1) 원본 변수 추출
MODULE_RAW=$(echo "$LINE" | awk '{print $1}') # 예: "core.data"
TEST_CLASS_RAW=$(echo "$LINE" | awk '{print $2}') # 예: "kr.co.data.dummy.DummyInstances"
MODULE_RAW=$(echo "$LINE" | awk '{print $1}')
TEST_CLASS_RAW=$(echo "$LINE" | awk '{print $2}')
echo "MODULE_RAW: $MODULE_RAW"
echo "TEST_CLASS_RAW: $TEST_CLASS_RAW"

Expand Down Expand Up @@ -104,4 +104,75 @@ jobs:
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: "**/test-results/**/*.xml"
files: "**/test-results/**/*.xml"

android_test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get changed files
id: changed_files
uses: tj-actions/changed-files@v45

- name: Filter out test files
id: android_test_files
run: |
echo "Changed files: ${{ steps.changed_files.outputs.all_changed_files }}"

ANDROID_TEST_FILES=$(echo "${{ steps.changed_files.outputs.all_changed_files }}" \
| tr ' ' '\n' \
| grep -E '^.+/src/androidTest/(java|kotlin)/.+\.(kt|java)$' || true)
echo "Filtered by grep: $ANDROID_TEST_FILES"

ANDROID_TEST_FILES=$(echo "$ANDROID_TEST_FILES" \
| sed -E 's/^(.+)\/src\/androidTest\/(java|kotlin)\/(.+)\.(kt|java)$/\1 \3/' \
| sed 's/\//./g')
echo "Processed by sed: $ANDROID_TEST_FILES"

ANDROID_TEST_FILES_SINGLE_LINE=$(echo "$ANDROID_TEST_FILES" | tr '\n' ' ')
echo "ANDROID_TEST_FILES=$ANDROID_TEST_FILES_SINGLE_LINE" >> $GITHUB_ENV

echo "$ANDROID_TEST_FILES" > android_test_files.txt

if [ -n "$(cat android_test_files.txt | xargs)" ]; then
echo "any_changed=true" >> $GITHUB_ENV
else
echo "any_changed=false" >> $GITHUB_ENV
fi

- name: Setup JDK
if: env.any_changed == 'true'
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'

- name: Grant execute permission for gradlew
if: env.any_changed == 'true'
run: chmod +x gradlew

- name: Run Instrumentation Tests on Emulator
if: env.any_changed == 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 26
target: default
arch: x86_64
profile: Nexus 6
script: ./gradlew connectedCheck --stacktrace
run: |
cat android_test_files.txt | while IFS=$'\n' read -r LINE; do
MODULE=$(echo "$LINE" | awk '{print $1}')
TEST_CLASS=$(echo "$LINE" | awk '{print $2}')

MODULE=$(echo "$MODULE" | sed 's|\.|:|g')

echo "MODULE: $MODULE"
echo "TEST_CLASS: $TEST_CLASS"

echo "Running: ./gradlew :$MODULE:connectedAndroidTest --tests \"$TEST_CLASS\""
./gradlew :$MODULE:connectedAndroidTest --tests "$TEST_CLASS" --scan || exit 1
done
35 changes: 33 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit Test
name: Test

on:
pull_request:
Expand Down Expand Up @@ -31,4 +31,35 @@ jobs:
- name: Test Result
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: "**/test-results/**/*.xml"
files: "**/test-results/**/*.xml"

android_test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'

- name: Setup Android SDK
uses: android-actions/setup-android@v3
with:
api-level: 26
target: 'default'
emulator: true

- name: Run Instrumentation Tests on Emulator
if: env.any_changed == 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 26
target: default
arch: x86_64
profile: Nexus 6
script: ./gradlew connectedCheck --stacktrace
run: ./gradlew connectedAndroidTest
Loading