From de2728104e997f595993315b90de773a4b0a7365 Mon Sep 17 00:00:00 2001 From: Viktor Benei Date: Mon, 24 Jan 2022 23:31:42 +0100 Subject: [PATCH] [BINS-246] Fixing missing skipped test in XCResult3 (#151) * [BINS-246] Fixing missing skipped test in XCResult3 * moving testdata xcresult3 out of the repo moving it into the https://github.com/bitrise-io/sample-artifacts --- bitrise.yml | 14 ++-- test/converters/xcresult3/converter.go | 6 ++ test/converters/xcresult3/converter_test.go | 79 +++++++++++++++++++++ 3 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 test/converters/xcresult3/converter_test.go diff --git a/bitrise.yml b/bitrise.yml index 7489d1da..369c1cf3 100644 --- a/bitrise.yml +++ b/bitrise.yml @@ -171,18 +171,24 @@ workflows: echo "-> BITRISE_PUBLIC_INSTALL_PAGE_URL: ${BITRISE_PUBLIC_INSTALL_PAGE_URL}" echo "-> BITRISE_PUBLIC_INSTALL_PAGE_URL_MAP: ${BITRISE_PUBLIC_INSTALL_PAGE_URL_MAP}" echo "-> BITRISE_PERMANENT_DOWNLOAD_URL_MAP: ${BITRISE_PERMANENT_DOWNLOAD_URL_MAP}" - test: + download_sample_artifacts: steps: - script: inputs: - content: |- #!/bin/bash - set -e - set -v + set -ex rm -rf ./_tmp - script: inputs: - - content: git clone --depth 1 $SAMPLE_ARTIFACTS_GIT_CLONE_URL ./_tmp + - content: | + #!/bin/bash + set -ex + git clone --depth 1 $SAMPLE_ARTIFACTS_GIT_CLONE_URL ./_tmp + test: + before_run: + - download_sample_artifacts + steps: - go-list: - golint: - errcheck: diff --git a/test/converters/xcresult3/converter.go b/test/converters/xcresult3/converter.go index b69e2a5e..385e2350 100644 --- a/test/converters/xcresult3/converter.go +++ b/test/converters/xcresult3/converter.go @@ -123,10 +123,16 @@ func (c *Converter) XML() (junit.XML, error) { } } + var skipped *junit.Skipped + if test.TestStatus.Value == "Skipped" { + skipped = &junit.Skipped{} + } + testSuit.TestCases = append(testSuit.TestCases, junit.TestCase{ Name: test.Name.Value, ClassName: strings.Split(test.Identifier.Value, "/")[0], Failure: failure, + Skipped: skipped, Time: duartion, }) diff --git a/test/converters/xcresult3/converter_test.go b/test/converters/xcresult3/converter_test.go new file mode 100644 index 00000000..f773ec04 --- /dev/null +++ b/test/converters/xcresult3/converter_test.go @@ -0,0 +1,79 @@ +package xcresult3 + +import ( + "os" + "path/filepath" + "testing" + + "github.com/bitrise-io/go-utils/command" + "github.com/bitrise-io/go-utils/pathutil" + "github.com/bitrise-steplib/steps-deploy-to-bitrise-io/test/junit" + "github.com/stretchr/testify/require" +) + +// copyTestdataToDir ... +// To populate the _tmp dir with sample data +// run `bitrise run download_sample_artifacts` before running tests here, +// which will download https://github.com/bitrise-io/sample-artifacts +// into the _tmp dir. +func copyTestdataToDir(t *testing.T, pathInTestdataDir, dirPathToCopyInto string) string { + err := command.CopyDir( + filepath.Join("../../../_tmp/", pathInTestdataDir), + dirPathToCopyInto, + true, + ) + require.NoError(t, err) + return dirPathToCopyInto +} + +func TestConverter_XML(t *testing.T) { + t.Run("xcresults3 success-failed-skipped-tests.xcresult", func(t *testing.T) { + // copy test data to tmp dir + tempTestdataDir, err := pathutil.NormalizedOSTempDirPath("test") + if err != nil { + t.Fatal("failed to create temp dir, error:", err) + } + defer func() { + require.NoError(t, os.RemoveAll(tempTestdataDir)) + }() + t.Log("tempTestdataDir: ", tempTestdataDir) + tempXCResultPath := copyTestdataToDir(t, "./xcresults/xcresult3-success-failed-skipped-tests.xcresult", tempTestdataDir) + + c := Converter{ + xcresultPth: tempXCResultPath, + } + junitXML, err := c.XML() + require.NoError(t, err) + require.Equal(t, []junit.TestSuite{ + junit.TestSuite{ + Name: "testProjectUITests", + Tests: 3, + Failures: 1, + Skipped: 1, + Errors: 0, + Time: 0.43262600898742676, + TestCases: []junit.TestCase{ + junit.TestCase{ + Name: "testFailure()", + ClassName: "testProjectUITests", + Time: 0.2580660581588745, + Failure: &junit.Failure{ + Value: "file:///Users/alexeysomov/Library/Autosave%20Information/testProject/testProjectUITests/testProjectUITests.swift:CharacterRangeLen=0&EndingLineNumber=29&StartingLineNumber=29 - XCTAssertTrue failed", + }, + }, + junit.TestCase{ + Name: "testSkip()", + ClassName: "testProjectUITests", + Time: 0.08595001697540283, + Skipped: &junit.Skipped{}, + }, + junit.TestCase{ + Name: "testSuccess()", + ClassName: "testProjectUITests", + Time: 0.08860993385314941, + }, + }, + }, + }, junitXML.TestSuites) + }) +}