Skip to content

Commit

Permalink
[BINS-246] Fixing missing skipped test in XCResult3 (#151)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
viktorbenei authored Jan 24, 2022
1 parent a5dd08d commit de27281
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
14 changes: 10 additions & 4 deletions bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions test/converters/xcresult3/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

Expand Down
79 changes: 79 additions & 0 deletions test/converters/xcresult3/converter_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}

0 comments on commit de27281

Please sign in to comment.