How to run/terminate shell command when starting/finishing iOS tests?












1















I am trying to write an integration test for my iOS app & our API server. Both are in the same repo, so this test would prevent merging any changes that would break their ability to communicate.



The server team has created a bash script that I need to call to start a local copy of the API server. That script will run until it is terminated. How can I run that script when I run my iOS integration test? I can't put it as part of the build phase as the build will wait for it to terminate before it lets the build finish. I can't use Process directly in my tests to launch the script because that's only available on the Mac, not to iOS targets. Refactoring all my networking & model code to it's own framework that supports iOS & Mac targets would work, but that's a sizable refactor to do. Are there any other ways to run commands along with tests? I'm just using XCTest for all my tests.










share|improve this question























  • Can you move the whole integration test into a wrapper script that first runs your server team's script and then the unit tests, e.g. using fastlane?

    – Gereon
    Dec 31 '18 at 14:54











  • Never used Fastlane, and from a quick scan of it's site, it doesn't sound like something they support. ¯_(ツ)_/¯

    – jamone
    Dec 31 '18 at 15:07











  • Fastlane has a sh command to run arbitrary things, but that's not what I meant. My suggestion was to write a shell script that does three things: 1) run your server script in the background and capture its PID. 2) run your tests. 3) kill the server script.

    – Gereon
    Dec 31 '18 at 15:12











  • If this shell script is what runs the tests now, wouldn't that break Xcode integration? How would you run/see results in Xcode then?

    – jamone
    Dec 31 '18 at 15:22






  • 1





    Yes. But nevermind, I think you should be able to do this by adding Pre- and Post-Actions to your tests. Go to "Edit Scheme" and click the triangle next to the Test scheme to see these. The "Pre-Action" would be to start the server and write its PID to a temp file somewhere. In the Post-Action read that PID file and kill the server.

    – Gereon
    Dec 31 '18 at 15:45
















1















I am trying to write an integration test for my iOS app & our API server. Both are in the same repo, so this test would prevent merging any changes that would break their ability to communicate.



The server team has created a bash script that I need to call to start a local copy of the API server. That script will run until it is terminated. How can I run that script when I run my iOS integration test? I can't put it as part of the build phase as the build will wait for it to terminate before it lets the build finish. I can't use Process directly in my tests to launch the script because that's only available on the Mac, not to iOS targets. Refactoring all my networking & model code to it's own framework that supports iOS & Mac targets would work, but that's a sizable refactor to do. Are there any other ways to run commands along with tests? I'm just using XCTest for all my tests.










share|improve this question























  • Can you move the whole integration test into a wrapper script that first runs your server team's script and then the unit tests, e.g. using fastlane?

    – Gereon
    Dec 31 '18 at 14:54











  • Never used Fastlane, and from a quick scan of it's site, it doesn't sound like something they support. ¯_(ツ)_/¯

    – jamone
    Dec 31 '18 at 15:07











  • Fastlane has a sh command to run arbitrary things, but that's not what I meant. My suggestion was to write a shell script that does three things: 1) run your server script in the background and capture its PID. 2) run your tests. 3) kill the server script.

    – Gereon
    Dec 31 '18 at 15:12











  • If this shell script is what runs the tests now, wouldn't that break Xcode integration? How would you run/see results in Xcode then?

    – jamone
    Dec 31 '18 at 15:22






  • 1





    Yes. But nevermind, I think you should be able to do this by adding Pre- and Post-Actions to your tests. Go to "Edit Scheme" and click the triangle next to the Test scheme to see these. The "Pre-Action" would be to start the server and write its PID to a temp file somewhere. In the Post-Action read that PID file and kill the server.

    – Gereon
    Dec 31 '18 at 15:45














1












1








1








I am trying to write an integration test for my iOS app & our API server. Both are in the same repo, so this test would prevent merging any changes that would break their ability to communicate.



The server team has created a bash script that I need to call to start a local copy of the API server. That script will run until it is terminated. How can I run that script when I run my iOS integration test? I can't put it as part of the build phase as the build will wait for it to terminate before it lets the build finish. I can't use Process directly in my tests to launch the script because that's only available on the Mac, not to iOS targets. Refactoring all my networking & model code to it's own framework that supports iOS & Mac targets would work, but that's a sizable refactor to do. Are there any other ways to run commands along with tests? I'm just using XCTest for all my tests.










share|improve this question














I am trying to write an integration test for my iOS app & our API server. Both are in the same repo, so this test would prevent merging any changes that would break their ability to communicate.



The server team has created a bash script that I need to call to start a local copy of the API server. That script will run until it is terminated. How can I run that script when I run my iOS integration test? I can't put it as part of the build phase as the build will wait for it to terminate before it lets the build finish. I can't use Process directly in my tests to launch the script because that's only available on the Mac, not to iOS targets. Refactoring all my networking & model code to it's own framework that supports iOS & Mac targets would work, but that's a sizable refactor to do. Are there any other ways to run commands along with tests? I'm just using XCTest for all my tests.







ios swift macos testing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 31 '18 at 14:46









jamonejamone

10.5k155185




10.5k155185













  • Can you move the whole integration test into a wrapper script that first runs your server team's script and then the unit tests, e.g. using fastlane?

    – Gereon
    Dec 31 '18 at 14:54











  • Never used Fastlane, and from a quick scan of it's site, it doesn't sound like something they support. ¯_(ツ)_/¯

    – jamone
    Dec 31 '18 at 15:07











  • Fastlane has a sh command to run arbitrary things, but that's not what I meant. My suggestion was to write a shell script that does three things: 1) run your server script in the background and capture its PID. 2) run your tests. 3) kill the server script.

    – Gereon
    Dec 31 '18 at 15:12











  • If this shell script is what runs the tests now, wouldn't that break Xcode integration? How would you run/see results in Xcode then?

    – jamone
    Dec 31 '18 at 15:22






  • 1





    Yes. But nevermind, I think you should be able to do this by adding Pre- and Post-Actions to your tests. Go to "Edit Scheme" and click the triangle next to the Test scheme to see these. The "Pre-Action" would be to start the server and write its PID to a temp file somewhere. In the Post-Action read that PID file and kill the server.

    – Gereon
    Dec 31 '18 at 15:45



















  • Can you move the whole integration test into a wrapper script that first runs your server team's script and then the unit tests, e.g. using fastlane?

    – Gereon
    Dec 31 '18 at 14:54











  • Never used Fastlane, and from a quick scan of it's site, it doesn't sound like something they support. ¯_(ツ)_/¯

    – jamone
    Dec 31 '18 at 15:07











  • Fastlane has a sh command to run arbitrary things, but that's not what I meant. My suggestion was to write a shell script that does three things: 1) run your server script in the background and capture its PID. 2) run your tests. 3) kill the server script.

    – Gereon
    Dec 31 '18 at 15:12











  • If this shell script is what runs the tests now, wouldn't that break Xcode integration? How would you run/see results in Xcode then?

    – jamone
    Dec 31 '18 at 15:22






  • 1





    Yes. But nevermind, I think you should be able to do this by adding Pre- and Post-Actions to your tests. Go to "Edit Scheme" and click the triangle next to the Test scheme to see these. The "Pre-Action" would be to start the server and write its PID to a temp file somewhere. In the Post-Action read that PID file and kill the server.

    – Gereon
    Dec 31 '18 at 15:45

















Can you move the whole integration test into a wrapper script that first runs your server team's script and then the unit tests, e.g. using fastlane?

– Gereon
Dec 31 '18 at 14:54





Can you move the whole integration test into a wrapper script that first runs your server team's script and then the unit tests, e.g. using fastlane?

– Gereon
Dec 31 '18 at 14:54













Never used Fastlane, and from a quick scan of it's site, it doesn't sound like something they support. ¯_(ツ)_/¯

– jamone
Dec 31 '18 at 15:07





Never used Fastlane, and from a quick scan of it's site, it doesn't sound like something they support. ¯_(ツ)_/¯

– jamone
Dec 31 '18 at 15:07













Fastlane has a sh command to run arbitrary things, but that's not what I meant. My suggestion was to write a shell script that does three things: 1) run your server script in the background and capture its PID. 2) run your tests. 3) kill the server script.

– Gereon
Dec 31 '18 at 15:12





Fastlane has a sh command to run arbitrary things, but that's not what I meant. My suggestion was to write a shell script that does three things: 1) run your server script in the background and capture its PID. 2) run your tests. 3) kill the server script.

– Gereon
Dec 31 '18 at 15:12













If this shell script is what runs the tests now, wouldn't that break Xcode integration? How would you run/see results in Xcode then?

– jamone
Dec 31 '18 at 15:22





If this shell script is what runs the tests now, wouldn't that break Xcode integration? How would you run/see results in Xcode then?

– jamone
Dec 31 '18 at 15:22




1




1





Yes. But nevermind, I think you should be able to do this by adding Pre- and Post-Actions to your tests. Go to "Edit Scheme" and click the triangle next to the Test scheme to see these. The "Pre-Action" would be to start the server and write its PID to a temp file somewhere. In the Post-Action read that PID file and kill the server.

– Gereon
Dec 31 '18 at 15:45





Yes. But nevermind, I think you should be able to do this by adding Pre- and Post-Actions to your tests. Go to "Edit Scheme" and click the triangle next to the Test scheme to see these. The "Pre-Action" would be to start the server and write its PID to a temp file somewhere. In the Post-Action read that PID file and kill the server.

– Gereon
Dec 31 '18 at 15:45












1 Answer
1






active

oldest

votes


















0














As mentioned in the comments I found a way to run scripts on test start & finish. You have to do it for the entire test target not the individual test cases.



You have to edit the scheme, expand the tests and add pre-actions & post-actions.



enter image description here






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988692%2fhow-to-run-terminate-shell-command-when-starting-finishing-ios-tests%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









    0














    As mentioned in the comments I found a way to run scripts on test start & finish. You have to do it for the entire test target not the individual test cases.



    You have to edit the scheme, expand the tests and add pre-actions & post-actions.



    enter image description here






    share|improve this answer




























      0














      As mentioned in the comments I found a way to run scripts on test start & finish. You have to do it for the entire test target not the individual test cases.



      You have to edit the scheme, expand the tests and add pre-actions & post-actions.



      enter image description here






      share|improve this answer


























        0












        0








        0







        As mentioned in the comments I found a way to run scripts on test start & finish. You have to do it for the entire test target not the individual test cases.



        You have to edit the scheme, expand the tests and add pre-actions & post-actions.



        enter image description here






        share|improve this answer













        As mentioned in the comments I found a way to run scripts on test start & finish. You have to do it for the entire test target not the individual test cases.



        You have to edit the scheme, expand the tests and add pre-actions & post-actions.



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 31 '18 at 19:07









        jamonejamone

        10.5k155185




        10.5k155185
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53988692%2fhow-to-run-terminate-shell-command-when-starting-finishing-ios-tests%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'