locked
How to test async function and task using Unit Test Library (Windows Store apps)?

    Question

  • Hi,

    I use ppltask library to implement some async function in my WinRT component. And I want to make a unit test for the function using Unit Test Library (Windows Store apps) that VS2012 provides. But I find if I call task::wait() function in a TestMethod, the method will crash!

    A simple demo is here:

    using namespace Microsoft::VisualStudio::CppUnitTestFramework;
    using namespace Sony::VAIO::SonySelect::ImageManager;
    using namespace concurrency;
    using namespace std;
    using namespace Platform;
    
    namespace UnitTestLibrary
    {
        TEST_CLASS(UnitTest1)
        {
        public:
            TEST_METHOD(TestMethod1)
            {
                auto readTask  = create_task([]() -> String^
                {
                    return "Test Async";
                });
    
                readTask.wait();
                auto str = readTask.get();
            }
        };
    }

    I'm newbie for Unit Test Library (Windows Store apps). If I cannot call task::wait() function in the test method, how can I make an unit test for my async functions in WinRT component?

    Wednesday, October 30, 2013 5:16 AM

All replies