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

[SR-14839] Running framework tests in Xcode not finding test resources #4410

Closed
swift-ci opened this issue Jun 28, 2021 · 2 comments
Closed
Labels

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-14839
Radar rdar://problem/79922202
Original Reporter stevex (JIRA User)
Type Bug
Status Resolved
Resolution Invalid

Attachment: Download

Environment

Xcode 13 beta 2
macOS 11.4

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: 63d25bf3a745c8b1c9e87527c1f4e9fc

Issue Description:

Sample Framework project attached. It includes resources in a testTarget via .copy, but they don't seem to be available when running the tests.

To reproduce:

  • Open the Package.swift file with Xcode

  • Select an iOS simulator as the run destination

  • Select Test on the Product menu.

The test fails because it can't find "astros.json", but it's in a subdirectory of "TestFiles" in "StructureCoreTests".

This may be an error on my part but I don't see where it's going wrong.

@typesanitizer
Copy link

@swift-ci create

@neonichu
Copy link
Member

There are two issues in the tests of the given package:

  • Package resources are part of a separate module that can be accessed using `Bundle.module`

  • You are copying a whole hierarchy of files, so you need a more concrete path

This diff makes the test run successfully:

diff --git a/Tests/StructureCoreTests/ImportJSONTest.swift b/Tests/StructureCoreTests/ImportJSONTest.swift
index 693328c..eb5dc9b 100644
--- a/Tests/StructureCoreTests/ImportJSONTest.swift
+++ b/Tests/StructureCoreTests/ImportJSONTest.swift
@@ -15,8 +15,8 @@ enum ImportJSONTestError: Error {
 class ImportJSONTest: XCTestCase {
 
     func testReadJSONFiles() throws {
-        let bundle = Bundle.init(for: ImportJSONTest.self)
-        guard let _ = bundle.url(forResource: "astros.json", withExtension: nil) else {
+        let bundle = Bundle.module
+        guard let _ = bundle.url(forResource: "TestFiles/Data/astros.json", withExtension: nil) else {
             // file not found
             throw ImportJSONTestError.reading
         }

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants