How to call the Assert::ExpectException correctly?Function Pointers in C++/CXHow do I test a private function or a class that has private methods, fields or inner classes?How do you set, clear, and toggle a single bit?How do you assert that a certain exception is thrown in JUnit 4 tests?How do I iterate over the words of a string?How can I safely create a nested directory?How do I use Assert to verify that an exception has been thrown?Best practice for Python assertWhat is the role of asserts in C++ programs that have unit tests?Is it possible to check if shared pointer returns a nullptr in native unit test?One class method call another one via function pointer

Make the `diff` command look only for differences from a specified range of lines

Can diplomats be allowed on the flight deck of a commercial European airline?

Is ideal gas incompressible?

How did the Allies achieve air superiority on Sicily?

What does it mean when みたいな is at the end of a sentence?

Writing "hahaha" versus describing the laugh

Proto-Indo-European (PIE) words with IPA

Is it OK to look at the list of played moves during the game to determine the status of the 50 move rule?

One word for 'the thing that attracts me'?

How to become an Editorial board member?

Is it normal to "extract a paper" from a master thesis?

What pc resources are used when bruteforcing?

How does the Earth's center produce heat?

How to tease a romance without a cat and mouse chase?

Illustrating that universal optimality is stronger than sphere packing

What does it mean for something to be strictly less than epsilon for an arbitrary epsilon?

Is it safe to redirect stdout and stderr to the same file without file descriptor copies?

Real Analysis: Proof of the equivalent definitions of the derivative.

Existence of a model of ZFC in which the natural numbers are really the natural numbers

Ratings matrix plot

Download app bundles from App Store to run on iOS Emulator on Mac

Is there a word for pant sleeves?

why "American-born", not "America-born"?

Gas chromatography flame ionization detector (FID) - why hydrogen gas?



How to call the Assert::ExpectException correctly?


Function Pointers in C++/CXHow do I test a private function or a class that has private methods, fields or inner classes?How do you set, clear, and toggle a single bit?How do you assert that a certain exception is thrown in JUnit 4 tests?How do I iterate over the words of a string?How can I safely create a nested directory?How do I use Assert to verify that an exception has been thrown?Best practice for Python assertWhat is the role of asserts in C++ programs that have unit tests?Is it possible to check if shared pointer returns a nullptr in native unit test?One class method call another one via function pointer






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I'm writing some unit tests using Microsoft's CppUnitTestFramework.



I want to test, if the method I call throws the correct exception. My code is:



TEST_METHOD(test_for_correct_exception_by_input_with_whitespaces)

std::string input "meet me at the corner" ;
Assert::ExpectException<std::invalid_argument>(AutokeyCipher::encrypt(input, primer));



In the link below I wrote the call similar to the last answer:



Function Pointers in C++/CX



When compiling it, I get the C2064 Error: term does not evaluate to a function taking 0 arguments



Why isn't that working?










share|improve this question
























  • "Why isn't that working?" How exactly isn't it working?

    – πάντα ῥεῖ
    Jan 19 at 14:31











  • Oh Sry, you are Right, forgot to write that information to the post. Wait, I’ll edit it!

    – Gino Pensuni
    Jan 19 at 14:33











  • really no one who can help?

    – Gino Pensuni
    Jan 19 at 16:24






  • 1





    Just be patient.

    – πάντα ῥεῖ
    Jan 19 at 16:31

















1















I'm writing some unit tests using Microsoft's CppUnitTestFramework.



I want to test, if the method I call throws the correct exception. My code is:



TEST_METHOD(test_for_correct_exception_by_input_with_whitespaces)

std::string input "meet me at the corner" ;
Assert::ExpectException<std::invalid_argument>(AutokeyCipher::encrypt(input, primer));



In the link below I wrote the call similar to the last answer:



Function Pointers in C++/CX



When compiling it, I get the C2064 Error: term does not evaluate to a function taking 0 arguments



Why isn't that working?










share|improve this question
























  • "Why isn't that working?" How exactly isn't it working?

    – πάντα ῥεῖ
    Jan 19 at 14:31











  • Oh Sry, you are Right, forgot to write that information to the post. Wait, I’ll edit it!

    – Gino Pensuni
    Jan 19 at 14:33











  • really no one who can help?

    – Gino Pensuni
    Jan 19 at 16:24






  • 1





    Just be patient.

    – πάντα ῥεῖ
    Jan 19 at 16:31













1












1








1








I'm writing some unit tests using Microsoft's CppUnitTestFramework.



I want to test, if the method I call throws the correct exception. My code is:



TEST_METHOD(test_for_correct_exception_by_input_with_whitespaces)

std::string input "meet me at the corner" ;
Assert::ExpectException<std::invalid_argument>(AutokeyCipher::encrypt(input, primer));



In the link below I wrote the call similar to the last answer:



Function Pointers in C++/CX



When compiling it, I get the C2064 Error: term does not evaluate to a function taking 0 arguments



Why isn't that working?










share|improve this question
















I'm writing some unit tests using Microsoft's CppUnitTestFramework.



I want to test, if the method I call throws the correct exception. My code is:



TEST_METHOD(test_for_correct_exception_by_input_with_whitespaces)

std::string input "meet me at the corner" ;
Assert::ExpectException<std::invalid_argument>(AutokeyCipher::encrypt(input, primer));



In the link below I wrote the call similar to the last answer:



Function Pointers in C++/CX



When compiling it, I get the C2064 Error: term does not evaluate to a function taking 0 arguments



Why isn't that working?







c++ unit-testing exception assertion microsoft-cpp-unit-test






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 14:35







Gino Pensuni

















asked Jan 19 at 14:28









Gino PensuniGino Pensuni

102112




102112












  • "Why isn't that working?" How exactly isn't it working?

    – πάντα ῥεῖ
    Jan 19 at 14:31











  • Oh Sry, you are Right, forgot to write that information to the post. Wait, I’ll edit it!

    – Gino Pensuni
    Jan 19 at 14:33











  • really no one who can help?

    – Gino Pensuni
    Jan 19 at 16:24






  • 1





    Just be patient.

    – πάντα ῥεῖ
    Jan 19 at 16:31

















  • "Why isn't that working?" How exactly isn't it working?

    – πάντα ῥεῖ
    Jan 19 at 14:31











  • Oh Sry, you are Right, forgot to write that information to the post. Wait, I’ll edit it!

    – Gino Pensuni
    Jan 19 at 14:33











  • really no one who can help?

    – Gino Pensuni
    Jan 19 at 16:24






  • 1





    Just be patient.

    – πάντα ῥεῖ
    Jan 19 at 16:31
















"Why isn't that working?" How exactly isn't it working?

– πάντα ῥεῖ
Jan 19 at 14:31





"Why isn't that working?" How exactly isn't it working?

– πάντα ῥεῖ
Jan 19 at 14:31













Oh Sry, you are Right, forgot to write that information to the post. Wait, I’ll edit it!

– Gino Pensuni
Jan 19 at 14:33





Oh Sry, you are Right, forgot to write that information to the post. Wait, I’ll edit it!

– Gino Pensuni
Jan 19 at 14:33













really no one who can help?

– Gino Pensuni
Jan 19 at 16:24





really no one who can help?

– Gino Pensuni
Jan 19 at 16:24




1




1





Just be patient.

– πάντα ῥεῖ
Jan 19 at 16:31





Just be patient.

– πάντα ῥεῖ
Jan 19 at 16:31












1 Answer
1






active

oldest

votes


















2














You need to wrap the code under test in a lambda expression to be called by the Assert::ExpectException function.



void Foo()

throw std::invalid_argument("test");


TEST_METHOD(Foo_ThrowsException)

auto func = [] Foo(); ;
Assert::ExpectException<std::invalid_argument>(func);






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%2f54268091%2fhow-to-call-the-assertexpectexception-correctly%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









    2














    You need to wrap the code under test in a lambda expression to be called by the Assert::ExpectException function.



    void Foo()

    throw std::invalid_argument("test");


    TEST_METHOD(Foo_ThrowsException)

    auto func = [] Foo(); ;
    Assert::ExpectException<std::invalid_argument>(func);






    share|improve this answer



























      2














      You need to wrap the code under test in a lambda expression to be called by the Assert::ExpectException function.



      void Foo()

      throw std::invalid_argument("test");


      TEST_METHOD(Foo_ThrowsException)

      auto func = [] Foo(); ;
      Assert::ExpectException<std::invalid_argument>(func);






      share|improve this answer

























        2












        2








        2







        You need to wrap the code under test in a lambda expression to be called by the Assert::ExpectException function.



        void Foo()

        throw std::invalid_argument("test");


        TEST_METHOD(Foo_ThrowsException)

        auto func = [] Foo(); ;
        Assert::ExpectException<std::invalid_argument>(func);






        share|improve this answer













        You need to wrap the code under test in a lambda expression to be called by the Assert::ExpectException function.



        void Foo()

        throw std::invalid_argument("test");


        TEST_METHOD(Foo_ThrowsException)

        auto func = [] Foo(); ;
        Assert::ExpectException<std::invalid_argument>(func);







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 21:11









        Chris OlsenChris Olsen

        1,6061123




        1,6061123





























            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%2f54268091%2fhow-to-call-the-assertexpectexception-correctly%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript