Xcode 10: Load the same .xml file in project target and unit test target
up vote
0
down vote
favorite
I try to load the same .xml file in project target and unit test target.
It seems to be a similar problem like this question: Xcode. Image resources added to a test target are not copied into the tests bundle
In project target, this code snipped worked fine. I just have to add the "xmlString.xml" file to "Copy Files" (see image 1).
func parseFile() {
let stringPath = Bundle.main.path(forResource: "xmlString", ofType: "xml")
let url = NSURL(fileURLWithPath: stringPath!)
...
}
If I run the code snipped in unit test target, I get an error because the .xml file can not be found. I tried to add the .xml file to the "Copy Bundle Resources" without any success (see image 2).
The only way to get it working is to use the absolute path
func parseFile() {
let stringPath: String? = "/Users/.../Documents/Git/.../.../.../.../xmlString.xml"
let url = NSURL(fileURLWithPath: stringPath!)
...
}
Is there a way to use the Bundle.main.path(forResource: "xmlString", ofType: "xml")
function instead of the absolute path?
Thanks in advance!
ios swift xcode macos unit-testing
add a comment |
up vote
0
down vote
favorite
I try to load the same .xml file in project target and unit test target.
It seems to be a similar problem like this question: Xcode. Image resources added to a test target are not copied into the tests bundle
In project target, this code snipped worked fine. I just have to add the "xmlString.xml" file to "Copy Files" (see image 1).
func parseFile() {
let stringPath = Bundle.main.path(forResource: "xmlString", ofType: "xml")
let url = NSURL(fileURLWithPath: stringPath!)
...
}
If I run the code snipped in unit test target, I get an error because the .xml file can not be found. I tried to add the .xml file to the "Copy Bundle Resources" without any success (see image 2).
The only way to get it working is to use the absolute path
func parseFile() {
let stringPath: String? = "/Users/.../Documents/Git/.../.../.../.../xmlString.xml"
let url = NSURL(fileURLWithPath: stringPath!)
...
}
Is there a way to use the Bundle.main.path(forResource: "xmlString", ofType: "xml")
function instead of the absolute path?
Thanks in advance!
ios swift xcode macos unit-testing
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I try to load the same .xml file in project target and unit test target.
It seems to be a similar problem like this question: Xcode. Image resources added to a test target are not copied into the tests bundle
In project target, this code snipped worked fine. I just have to add the "xmlString.xml" file to "Copy Files" (see image 1).
func parseFile() {
let stringPath = Bundle.main.path(forResource: "xmlString", ofType: "xml")
let url = NSURL(fileURLWithPath: stringPath!)
...
}
If I run the code snipped in unit test target, I get an error because the .xml file can not be found. I tried to add the .xml file to the "Copy Bundle Resources" without any success (see image 2).
The only way to get it working is to use the absolute path
func parseFile() {
let stringPath: String? = "/Users/.../Documents/Git/.../.../.../.../xmlString.xml"
let url = NSURL(fileURLWithPath: stringPath!)
...
}
Is there a way to use the Bundle.main.path(forResource: "xmlString", ofType: "xml")
function instead of the absolute path?
Thanks in advance!
ios swift xcode macos unit-testing
I try to load the same .xml file in project target and unit test target.
It seems to be a similar problem like this question: Xcode. Image resources added to a test target are not copied into the tests bundle
In project target, this code snipped worked fine. I just have to add the "xmlString.xml" file to "Copy Files" (see image 1).
func parseFile() {
let stringPath = Bundle.main.path(forResource: "xmlString", ofType: "xml")
let url = NSURL(fileURLWithPath: stringPath!)
...
}
If I run the code snipped in unit test target, I get an error because the .xml file can not be found. I tried to add the .xml file to the "Copy Bundle Resources" without any success (see image 2).
The only way to get it working is to use the absolute path
func parseFile() {
let stringPath: String? = "/Users/.../Documents/Git/.../.../.../.../xmlString.xml"
let url = NSURL(fileURLWithPath: stringPath!)
...
}
Is there a way to use the Bundle.main.path(forResource: "xmlString", ofType: "xml")
function instead of the absolute path?
Thanks in advance!
ios swift xcode macos unit-testing
ios swift xcode macos unit-testing
edited 2 days ago
asked 2 days ago
Passe
139116
139116
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can get the bundle for your project like this:
let projectBundle = Bundle(for: AnyClassInMyProject.self)
where you replace AnyClassInMyProject
with the name of an actual class in your project.
You can then get the path to your .xml file like this:
let stringPath = projectBundle.path(forResource: "xmlString", ofType: "xml")
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
Did you replaceAnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so,projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.
– Mike Taverne
2 days ago
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can get the bundle for your project like this:
let projectBundle = Bundle(for: AnyClassInMyProject.self)
where you replace AnyClassInMyProject
with the name of an actual class in your project.
You can then get the path to your .xml file like this:
let stringPath = projectBundle.path(forResource: "xmlString", ofType: "xml")
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
Did you replaceAnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so,projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.
– Mike Taverne
2 days ago
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
add a comment |
up vote
0
down vote
You can get the bundle for your project like this:
let projectBundle = Bundle(for: AnyClassInMyProject.self)
where you replace AnyClassInMyProject
with the name of an actual class in your project.
You can then get the path to your .xml file like this:
let stringPath = projectBundle.path(forResource: "xmlString", ofType: "xml")
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
Did you replaceAnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so,projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.
– Mike Taverne
2 days ago
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
You can get the bundle for your project like this:
let projectBundle = Bundle(for: AnyClassInMyProject.self)
where you replace AnyClassInMyProject
with the name of an actual class in your project.
You can then get the path to your .xml file like this:
let stringPath = projectBundle.path(forResource: "xmlString", ofType: "xml")
You can get the bundle for your project like this:
let projectBundle = Bundle(for: AnyClassInMyProject.self)
where you replace AnyClassInMyProject
with the name of an actual class in your project.
You can then get the path to your .xml file like this:
let stringPath = projectBundle.path(forResource: "xmlString", ofType: "xml")
answered 2 days ago
Mike Taverne
5,51821938
5,51821938
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
Did you replaceAnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so,projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.
– Mike Taverne
2 days ago
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
add a comment |
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
Did you replaceAnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so,projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.
– Mike Taverne
2 days ago
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
let projectBundle = NSBundle </Users/.../Library/Developer/Xcode/DerivedData/Pattern-chlgsqhxjngcwabmjgaujwwewapq/Build/Products/Debug/UnitTest.xctest> (loaded) what to do with this information?
– Passe
2 days ago
Did you replace
AnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so, projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.– Mike Taverne
2 days ago
Did you replace
AnyClassInMyProject
with the name of an actual class in your project? Your main project, not your test project? If so, projectBundle
will refer to the bundle for your main project, i.e. it will be the equivalent of calling Bundle.main in your main project.– Mike Taverne
2 days ago
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
Yes, I replaced "AnyClassInMyProject" with my XmlParser class in main project. So it seems to be completely wrong right? But why does it work in main target and not in test target? What do I have to change?
– Passe
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239259%2fxcode-10-load-the-same-xml-file-in-project-target-and-unit-test-target%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password