Why should I use a separate test host for running XCTests and how should I do that?
I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test host (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't
I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some articles explaining the issue will be much appreciated.
P.S. I understand that I need special environment for tests (fake in-memory database, mocked networking layer, etc.), but up until now I managed to achieve it without a separate test host, using just my main app, like the Xcode suggests by default. But I believe that there might be a better way. And I know that the defaults that Xcode suggests are not always that great.
ios unit-testing xctest
add a comment |
I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test host (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't
I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some articles explaining the issue will be much appreciated.
P.S. I understand that I need special environment for tests (fake in-memory database, mocked networking layer, etc.), but up until now I managed to achieve it without a separate test host, using just my main app, like the Xcode suggests by default. But I believe that there might be a better way. And I know that the defaults that Xcode suggests are not always that great.
ios unit-testing xctest
If you think you've seen this before: I've already asked a question with a very-very similar text. But because of my mistake it was about a separate test target, not about a separate test host. If you're wondering why I kept that question and created a new one, here's a meta question explaining my reasons.
– FreeNickname
Feb 19 '16 at 22:12
I'd suggest doing some research. There's an awful lot about this on the Interwebs...
– matt
Feb 19 '16 at 22:19
@matt, I always try to find an answer myself first, but this time I didn't succeed, unfortunately. It's hard to find information specifically about using a separate test host. Most articles focus on ways to add unit tests to an existing project, on different functions available in XCTests (Equal, EqualObjects, etc.) and everything else. That's why I asked for help here.
– FreeNickname
Feb 20 '16 at 8:22
add a comment |
I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test host (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't
I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some articles explaining the issue will be much appreciated.
P.S. I understand that I need special environment for tests (fake in-memory database, mocked networking layer, etc.), but up until now I managed to achieve it without a separate test host, using just my main app, like the Xcode suggests by default. But I believe that there might be a better way. And I know that the defaults that Xcode suggests are not always that great.
ios unit-testing xctest
I once asked a question related to XCTests. And in one of the answers I was told that it is a common practice to use a separate test host (other than the main app) when running unit tests (at least, in iOS development). I tried to find some sources about it, but I couldn't
I understand, that it is probably a best practice, so I would really like to understand it. Could someone explain to me why is it important, what benefits do I get from it and how should I go about doing it? Links to some articles explaining the issue will be much appreciated.
P.S. I understand that I need special environment for tests (fake in-memory database, mocked networking layer, etc.), but up until now I managed to achieve it without a separate test host, using just my main app, like the Xcode suggests by default. But I believe that there might be a better way. And I know that the defaults that Xcode suggests are not always that great.
ios unit-testing xctest
ios unit-testing xctest
edited May 23 '17 at 11:46
Community♦
11
11
asked Feb 19 '16 at 21:57
FreeNicknameFreeNickname
5,92321647
5,92321647
If you think you've seen this before: I've already asked a question with a very-very similar text. But because of my mistake it was about a separate test target, not about a separate test host. If you're wondering why I kept that question and created a new one, here's a meta question explaining my reasons.
– FreeNickname
Feb 19 '16 at 22:12
I'd suggest doing some research. There's an awful lot about this on the Interwebs...
– matt
Feb 19 '16 at 22:19
@matt, I always try to find an answer myself first, but this time I didn't succeed, unfortunately. It's hard to find information specifically about using a separate test host. Most articles focus on ways to add unit tests to an existing project, on different functions available in XCTests (Equal, EqualObjects, etc.) and everything else. That's why I asked for help here.
– FreeNickname
Feb 20 '16 at 8:22
add a comment |
If you think you've seen this before: I've already asked a question with a very-very similar text. But because of my mistake it was about a separate test target, not about a separate test host. If you're wondering why I kept that question and created a new one, here's a meta question explaining my reasons.
– FreeNickname
Feb 19 '16 at 22:12
I'd suggest doing some research. There's an awful lot about this on the Interwebs...
– matt
Feb 19 '16 at 22:19
@matt, I always try to find an answer myself first, but this time I didn't succeed, unfortunately. It's hard to find information specifically about using a separate test host. Most articles focus on ways to add unit tests to an existing project, on different functions available in XCTests (Equal, EqualObjects, etc.) and everything else. That's why I asked for help here.
– FreeNickname
Feb 20 '16 at 8:22
If you think you've seen this before: I've already asked a question with a very-very similar text. But because of my mistake it was about a separate test target, not about a separate test host. If you're wondering why I kept that question and created a new one, here's a meta question explaining my reasons.
– FreeNickname
Feb 19 '16 at 22:12
If you think you've seen this before: I've already asked a question with a very-very similar text. But because of my mistake it was about a separate test target, not about a separate test host. If you're wondering why I kept that question and created a new one, here's a meta question explaining my reasons.
– FreeNickname
Feb 19 '16 at 22:12
I'd suggest doing some research. There's an awful lot about this on the Interwebs...
– matt
Feb 19 '16 at 22:19
I'd suggest doing some research. There's an awful lot about this on the Interwebs...
– matt
Feb 19 '16 at 22:19
@matt, I always try to find an answer myself first, but this time I didn't succeed, unfortunately. It's hard to find information specifically about using a separate test host. Most articles focus on ways to add unit tests to an existing project, on different functions available in XCTests (Equal, EqualObjects, etc.) and everything else. That's why I asked for help here.
– FreeNickname
Feb 20 '16 at 8:22
@matt, I always try to find an answer myself first, but this time I didn't succeed, unfortunately. It's hard to find information specifically about using a separate test host. Most articles focus on ways to add unit tests to an existing project, on different functions available in XCTests (Equal, EqualObjects, etc.) and everything else. That's why I asked for help here.
– FreeNickname
Feb 20 '16 at 8:22
add a comment |
1 Answer
1
active
oldest
votes
Reasons to use a different host app for unit tests:
- There is no main app, because your target is a library.
- When the main app is launched, it goes through its start-up process. This takes too long, and has side-effects.
Reason 1 is pretty much a given. But what about reason 2?
My approach is to use the main app, but use a different application delegate during testing. That way I don't have to maintain a separate app, just an alternate start-up process. See How to Easily Switch Your App Delegate for Testing
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35515825%2fwhy-should-i-use-a-separate-test-host-for-running-xctests-and-how-should-i-do-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Reasons to use a different host app for unit tests:
- There is no main app, because your target is a library.
- When the main app is launched, it goes through its start-up process. This takes too long, and has side-effects.
Reason 1 is pretty much a given. But what about reason 2?
My approach is to use the main app, but use a different application delegate during testing. That way I don't have to maintain a separate app, just an alternate start-up process. See How to Easily Switch Your App Delegate for Testing
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
add a comment |
Reasons to use a different host app for unit tests:
- There is no main app, because your target is a library.
- When the main app is launched, it goes through its start-up process. This takes too long, and has side-effects.
Reason 1 is pretty much a given. But what about reason 2?
My approach is to use the main app, but use a different application delegate during testing. That way I don't have to maintain a separate app, just an alternate start-up process. See How to Easily Switch Your App Delegate for Testing
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
add a comment |
Reasons to use a different host app for unit tests:
- There is no main app, because your target is a library.
- When the main app is launched, it goes through its start-up process. This takes too long, and has side-effects.
Reason 1 is pretty much a given. But what about reason 2?
My approach is to use the main app, but use a different application delegate during testing. That way I don't have to maintain a separate app, just an alternate start-up process. See How to Easily Switch Your App Delegate for Testing
Reasons to use a different host app for unit tests:
- There is no main app, because your target is a library.
- When the main app is launched, it goes through its start-up process. This takes too long, and has side-effects.
Reason 1 is pretty much a given. But what about reason 2?
My approach is to use the main app, but use a different application delegate during testing. That way I don't have to maintain a separate app, just an alternate start-up process. See How to Easily Switch Your App Delegate for Testing
edited Nov 23 '18 at 19:38
answered Feb 20 '16 at 2:18
Jon ReidJon Reid
16k24978
16k24978
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
add a comment |
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
Using a separate app delegate makes sense, and this way I don't have to keep two hosts (the main app and the test host) in sync. Thank you!
– FreeNickname
Feb 20 '16 at 10:28
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35515825%2fwhy-should-i-use-a-separate-test-host-for-running-xctests-and-how-should-i-do-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you think you've seen this before: I've already asked a question with a very-very similar text. But because of my mistake it was about a separate test target, not about a separate test host. If you're wondering why I kept that question and created a new one, here's a meta question explaining my reasons.
– FreeNickname
Feb 19 '16 at 22:12
I'd suggest doing some research. There's an awful lot about this on the Interwebs...
– matt
Feb 19 '16 at 22:19
@matt, I always try to find an answer myself first, but this time I didn't succeed, unfortunately. It's hard to find information specifically about using a separate test host. Most articles focus on ways to add unit tests to an existing project, on different functions available in XCTests (Equal, EqualObjects, etc.) and everything else. That's why I asked for help here.
– FreeNickname
Feb 20 '16 at 8:22