From 0693733f633d66dc2611439d0d5dde4baa4c1b40 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 12 Aug 2024 09:55:46 +0200 Subject: [PATCH 1/7] Use `merge_junit_reports` script This script is provided by ci toolkit --- .buildkite/commands/run-unit-tests.sh | 2 +- merge_junit.sh | 40 --------------------------- 2 files changed, 1 insertion(+), 41 deletions(-) delete mode 100755 merge_junit.sh diff --git a/.buildkite/commands/run-unit-tests.sh b/.buildkite/commands/run-unit-tests.sh index 248b21a23cb..528101ceb8e 100755 --- a/.buildkite/commands/run-unit-tests.sh +++ b/.buildkite/commands/run-unit-tests.sh @@ -18,7 +18,7 @@ echo "--- 🚦 Report Tests Status" results_file="WooCommerce/build/test-results/merged-test-results.xml" # Merge JUnit results into a single file (for performance reasons with reporting) # See https://github.com/woocommerce/woocommerce-android/pull/12064 -./merge_junit.sh -d WooCommerce/build/test-results/testJalapenoDebugUnitTest -o $results_file +merge_junit_reports -d WooCommerce/build/test-results/testJalapenoDebugUnitTest -o $results_file if [[ $BUILDKITE_BRANCH == trunk ]] || [[ $BUILDKITE_BRANCH == release/* ]]; then annotate_test_failures "$results_file" --slack "build-and-ship" diff --git a/merge_junit.sh b/merge_junit.sh deleted file mode 100755 index b4935373939..00000000000 --- a/merge_junit.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Initialize variables -reports_dir="" -output_file="" - -# Function to show usage -usage() { - echo "Usage: $0 -d -o " - exit 1 -} - -# Parse command-line options -while getopts "d:o:" opt; do - case $opt in - d) reports_dir=$OPTARG ;; - o) output_file=$OPTARG ;; - ?) usage ;; - esac -done - -# Check if both arguments were provided -if [ -z "$reports_dir" ] || [ -z "$output_file" ]; then - usage -fi - -# Write XML header to the output file -echo '' > "$output_file" -echo '' >> "$output_file" - -# Merge the content of all input JUnit files in the directory. -# (Note that in the case of Unit Tests, the JUnit XML files produced by Gradle -# don't have a parent `` root tag, so there's no need to try and remove it) -sed '/<\?xml .*\?>/d' "$reports_dir"/*.xml >> "$output_file" - -# Close the testsuites tag -echo '' >> "$output_file" - -# Print the result -echo "Merged XML reports into $output_file" From ff4556961c02f62a3994284fe2f20d3e65cb9993 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 12 Aug 2024 09:57:57 +0200 Subject: [PATCH 2/7] Specify `result_file` as the file for test collector It's more readable this way --- .buildkite/commands/run-unit-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/commands/run-unit-tests.sh b/.buildkite/commands/run-unit-tests.sh index 528101ceb8e..bf5f14c056f 100755 --- a/.buildkite/commands/run-unit-tests.sh +++ b/.buildkite/commands/run-unit-tests.sh @@ -31,6 +31,6 @@ echo "--- ⚒️ Generating and uploading code coverage" .buildkite/commands/upload-code-coverage.sh echo "--- 🧪 Copying test logs for test collector" -mkdir WooCommerce/build/buildkite-test-analytics && cp WooCommerce/build/test-results/*.xml WooCommerce/build/buildkite-test-analytics +mkdir WooCommerce/build/buildkite-test-analytics && cp $results_file WooCommerce/build/buildkite-test-analytics exit $TESTS_EXIT_STATUS From 8ff2eceab485dfa2fcff0e87ee0c1d7100d6a455 Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 12 Aug 2024 09:59:59 +0200 Subject: [PATCH 3/7] Specify merged JUnit report file as the only artifact of unit tests job --- .buildkite/pipeline.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 34b7c6896e7..2a015a8a3bf 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -87,7 +87,7 @@ steps: <<: *test_collector_common_params api-token-env-name: "BUILDKITE_ANALYTICS_TOKEN_UNIT_TESTS" artifact_paths: - - "**/build/test-results/*/*.xml" + - "**/build/test-results/merged-test-results.xml" - label: "Instrumented tests" command: .buildkite/commands/run-instrumented-tests.sh From 5c026df11d775afd10ebad55a8786e332d22fa2d Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 12 Aug 2024 11:20:55 +0200 Subject: [PATCH 4/7] temp: break unit test To assert Buildkite annotation logic works as expected --- .../ui/orders/details/editing/address/AddressViewModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt index 305c1fb6da0..74c7d7ce936 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt @@ -112,7 +112,7 @@ class AddressViewModelTest : BaseUnitTest() { addressViewModel.start( mapOf(SHIPPING to shippingAddress) ) - verify(dataStore, times(2)).fetchCountriesAndStates(selectedSite.get()) + verify(dataStore, times(0)).fetchCountriesAndStates(selectedSite.get()) } } From 196488c3c2f03e6bcd28ebeadaa593140a63efbd Mon Sep 17 00:00:00 2001 From: Wojtek Zieba Date: Mon, 12 Aug 2024 11:54:15 +0200 Subject: [PATCH 5/7] Revert "temp: break unit test" This reverts commit 5c026df11d775afd10ebad55a8786e332d22fa2d. --- .../ui/orders/details/editing/address/AddressViewModelTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt index 74c7d7ce936..305c1fb6da0 100644 --- a/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt +++ b/WooCommerce/src/test/kotlin/com/woocommerce/android/ui/orders/details/editing/address/AddressViewModelTest.kt @@ -112,7 +112,7 @@ class AddressViewModelTest : BaseUnitTest() { addressViewModel.start( mapOf(SHIPPING to shippingAddress) ) - verify(dataStore, times(0)).fetchCountriesAndStates(selectedSite.get()) + verify(dataStore, times(2)).fetchCountriesAndStates(selectedSite.get()) } } From 3c24529fbcc0b1a3463d4c535fd4cc137cdb3c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Zi=C4=99ba?= Date: Mon, 12 Aug 2024 14:09:24 +0200 Subject: [PATCH 6/7] Update .buildkite/commands/run-unit-tests.sh Co-authored-by: Olivier Halligon --- .buildkite/commands/run-unit-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/commands/run-unit-tests.sh b/.buildkite/commands/run-unit-tests.sh index bf5f14c056f..d2b07274841 100755 --- a/.buildkite/commands/run-unit-tests.sh +++ b/.buildkite/commands/run-unit-tests.sh @@ -18,7 +18,7 @@ echo "--- 🚦 Report Tests Status" results_file="WooCommerce/build/test-results/merged-test-results.xml" # Merge JUnit results into a single file (for performance reasons with reporting) # See https://github.com/woocommerce/woocommerce-android/pull/12064 -merge_junit_reports -d WooCommerce/build/test-results/testJalapenoDebugUnitTest -o $results_file +merge_junit_reports -d WooCommerce/build/test-results/testJalapenoDebugUnitTest -o "$results_file" if [[ $BUILDKITE_BRANCH == trunk ]] || [[ $BUILDKITE_BRANCH == release/* ]]; then annotate_test_failures "$results_file" --slack "build-and-ship" From 67fbe10885620655c698e44bf3fafe2cc0a28f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Zi=C4=99ba?= Date: Mon, 12 Aug 2024 14:09:31 +0200 Subject: [PATCH 7/7] Update .buildkite/commands/run-unit-tests.sh Co-authored-by: Olivier Halligon --- .buildkite/commands/run-unit-tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/commands/run-unit-tests.sh b/.buildkite/commands/run-unit-tests.sh index d2b07274841..e1cba7b285d 100755 --- a/.buildkite/commands/run-unit-tests.sh +++ b/.buildkite/commands/run-unit-tests.sh @@ -31,6 +31,6 @@ echo "--- ⚒️ Generating and uploading code coverage" .buildkite/commands/upload-code-coverage.sh echo "--- 🧪 Copying test logs for test collector" -mkdir WooCommerce/build/buildkite-test-analytics && cp $results_file WooCommerce/build/buildkite-test-analytics +mkdir WooCommerce/build/buildkite-test-analytics && cp "$results_file" WooCommerce/build/buildkite-test-analytics exit $TESTS_EXIT_STATUS