Commits

Matt Oswald  committed 62104af

fixed (finally!) the visual studio test integration component

  • Participants
  • Parent commits 39c7170

Comments (0)

Files changed (4)

File xUnit++.VsRunner/xUnit++.VsRunner.cpp

 
 namespace
 {
+    String ^TestKey(const xUnitpp::ITestDetails &td)
+    {
+        return marshal_as<String ^>(td.GetFullName());
+    }
+
+    std::string DisplayName(const xUnitpp::ITestDetails &td)
+    {
+        std::string name = td.GetName();
+        if (!std::string(td.GetParams()).empty())
+        {
+            name += " [" + std::to_string(td.GetTestInstance()) + "]";
+        }
+
+        return name;
+    }
+
+    String ^TestName(const xUnitpp::ITestDetails &td)
+    {
+        return marshal_as<String ^>(DisplayName(td));
+    }
+
     ref class ManagedReporter
     {
     public:
         {
             for (auto &test : testCases)
             {
-                if (!this->testCases.ContainsKey(test->DisplayName))
-                this->testCases.Add(test->DisplayName, test);
+                if (!this->testCases.ContainsKey(test->FullyQualifiedName))
+                {
+                    this->testCases.Add(test->FullyQualifiedName, test);
+                }
             }
         }
 
         void ReportStart(const xUnitpp::ITestDetails &td)
         {
-            auto key = marshal_as<String ^>(td.GetFullName());
-            auto name = marshal_as<String ^>(td.GetName());
-            recorder->RecordStart(testCases[name]);
+            auto key = TestKey(td);
+            auto name = TestName(td);
+            recorder->RecordStart(testCases[key]);
 
-            auto result = gcnew TestResult(testCases[name]);
+            auto result = gcnew TestResult(testCases[key]);
             result->ComputerName = Environment::MachineName;
             result->DisplayName = name;
             result->Outcome = TestOutcome::None;
 
         void ReportEvent(const xUnitpp::ITestDetails &td, const xUnitpp::ITestEvent &evt)
         {
-            auto key = marshal_as<String ^>(td.GetName());
+            auto key = TestKey(td);
             auto result = testResults[key];
 
             if (evt.GetIsFailure())
 
         void ReportSkip(const xUnitpp::ITestDetails &td, const std::string &)
         {
-            auto key = marshal_as<String ^>(td.GetFullName());
+            auto key = TestKey(td);
             auto testCase = testCases[key];
             auto result = gcnew TestResult(testCase);
             result->ComputerName = Environment::MachineName;
-            result->DisplayName = marshal_as<String ^>(td.GetName());
+            result->DisplayName = TestName(td);
             result->Duration = TimeSpan::FromSeconds(0);
             result->Outcome = TestOutcome::Skipped;
             recorder->RecordEnd(testCase, result->Outcome);
 
         void ReportFinish(const xUnitpp::ITestDetails &td, xUnitpp::Time::Duration timeTaken)
         {
-            auto key = marshal_as<String ^>(td.GetFullName());
+            auto key = TestKey(td);
             auto result = testResults[key];
             result->Duration = TimeSpan::FromSeconds(xUnitpp::Time::ToSeconds(timeTaken).count());
 
                 result->Outcome = TestOutcome::Passed;
             }
 
-            recorder->RecordEnd(testCases[marshal_as<String ^>(td.GetFullName())], result->Outcome);
+            recorder->RecordEnd(testCases[key], result->Outcome);
             recorder->RecordResult(result);
         }
 
                     return !cancelled && std::find_if(tests.begin(), tests.end(),
                         [&](gcroot<TestCase ^> test)
                         {
-                            return marshal_as<std::string>(test->DisplayName) == testDetails.GetName();
+                            return test->DisplayName == TestName(testDetails);
                         }) != tests.end();
                 });
         }
         std::vector<gcroot<TestCase ^>> tests;
     };
 
-    IEnumerable<TestCase ^> ^SingleSourceTestCases(String ^_source, Uri ^_uri, IMessageLogger ^logger)
+    IEnumerable<TestCase ^> ^SingleSourceTestCases(String ^_source, Uri ^_uri)
     {
-        logger->SendMessage(TestMessageLevel::Informational, "Inside SingleSourceTestCases");
-
         auto results = gcnew List<TestCase ^>();
-
-        logger->SendMessage(TestMessageLevel::Informational, "SingleSourceTestCases _source: " + _source);
-
         auto source = marshal_as<std::string>(_source);
 
         if (auto assembly = ManagedTestAssembly(source))
             assembly.EnumerateTestDetails(
                 [&](const xUnitpp::ITestDetails &td)
                 {
-                    testDetails testDetails = { td.GetFullName(), td.GetName(), td.GetFile(), td.GetLine() };
+                    testDetails testDetails = { td.GetFullName(), DisplayName(td), td.GetFile(), td.GetLine() };
                     tests.push_back(testDetails);
                 });
 
 {
 }
 
-void xUnitppVsRunner::DiscoverTests(IEnumerable<String ^> ^sources, IDiscoveryContext ^, IMessageLogger ^logger, ITestCaseDiscoverySink ^discoverySink)
+void xUnitppVsRunner::DiscoverTests(IEnumerable<String ^> ^sources, IDiscoveryContext ^, IMessageLogger ^, ITestCaseDiscoverySink ^discoverySink)
 {
-    logger->SendMessage(TestMessageLevel::Informational, "Test discovery starting.");
-
-    try
-    {
-
     for each (String ^source in sources)
     {
-        logger->SendMessage(TestMessageLevel::Informational, source);
-        logger->SendMessage(TestMessageLevel::Informational, "about to call singlesourcetestcases");
-        for each (TestCase ^test in SingleSourceTestCases(source, mUri, logger))
+        for each (TestCase ^test in SingleSourceTestCases(source, mUri))
         {
             discoverySink->SendTestCase(test);
         }
     }
-
-    }
-    catch(Exception ^e)
-    {
-        logger->SendMessage(TestMessageLevel::Error, e->ToString());
-    }
-
-    logger->SendMessage(TestMessageLevel::Informational, "Test discovery finished.");
 }
 
 void xUnitppVsRunner::RunTests(IEnumerable<String ^> ^sources, IRunContext ^, IFrameworkHandle ^framework)
 
     for each (String ^source in sources)
     {
-        if (RunTests(SingleSourceTestCases(source, mUri, nullptr), framework))
+        if (RunTests(SingleSourceTestCases(source, mUri), framework))
         {
             // cancelled
             break;

File xUnit++/src/TestDetails.cpp

     return Suite.c_str();
 }
 
+const char * __stdcall TestDetails::GetParams() const
+{
+    return Params.c_str();
+}
+
+int __stdcall TestDetails::GetTestInstance() const
+{
+    return TestInstance;
+}
+
 size_t __stdcall TestDetails::GetAttributeCount() const 
 {
     return Attributes.size();

File xUnit++/xUnit++/ITestDetails.h

     virtual const char * __stdcall GetName() const = 0;
     virtual const char * __stdcall GetFullName() const = 0;
     virtual const char * __stdcall GetSuite() const = 0;
+    virtual const char * __stdcall GetParams() const = 0;
+    virtual int __stdcall GetTestInstance() const = 0;
     virtual size_t __stdcall GetAttributeCount() const = 0;
     virtual const char * __stdcall GetAttributeKey(size_t index) const = 0;
     virtual const char * __stdcall GetAttributeValue(size_t index) const = 0;

File xUnit++/xUnit++/TestDetails.h

     virtual const char * __stdcall GetName() const override;
     virtual const char * __stdcall GetFullName() const override;
     virtual const char * __stdcall GetSuite() const override;
+    virtual const char * __stdcall GetParams() const override;
+    virtual int __stdcall GetTestInstance() const override;
     virtual size_t __stdcall GetAttributeCount() const override;
     virtual const char * __stdcall GetAttributeKey(size_t index) const override;
     virtual const char * __stdcall GetAttributeValue(size_t index) const override;