1

I am not able to find something on the internet for the last hours. The situation is the following: I want to test a parser I have written, for this I have the desire to write a data driven unit test. The XML I have looks like the following:

<Test>
   <ParseTest>
      <Case>
         <uri>somestring</uri>
         <key>somestring</key>
         <value>somestring</value>
      </Case>
      <Case>
         <uri>somestring</uri>
         <key>somestring</key>
         <value>somestring</value>
      </Case>
   </ParseTest>
</Test>

Test is my root node for the whole class. The ParseTest should be the root for each method, so I want to access per run one case node with its childs

My testing code is:

[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML",@"PATH\name.xml","ParseTest",DataAccessMethod.Seqential)]
public void ParseTest()
{
   //Arrange       
      m_testContext.DataRow["uri"].ToString();
   //Act
   //Assert
}

Problem with it is, that the Framework does not find the correct childnodes. The file is found correctly. I run the test via “Run test“ in VS.

7
  • Could you elaborate a bit more what the error is? Does the test framework not find the test, or the file? How are you running your tests (re# for example is shadow-copying test assemblies, which can lead to such errors)? Have you tried debugging (or output Directory.GetCurrentDirectory())? Commented Apr 13, 2018 at 7:02
  • @PaulKertscher Better? Commented Apr 13, 2018 at 7:08
  • I am just looking up data driven tests with MSTest, gimme a sec. Commented Apr 13, 2018 at 7:09
  • How are you trying to access your test data? Commented Apr 13, 2018 at 7:15
  • I do not access the data. The MS Test Framework does this for me. Commented Apr 13, 2018 at 7:18

1 Answer 1

1

Following this example the additional ParseTest is redundant (or the nested Case tags are). As far as I have understood, the test framework will load all tags with the name ParseTest and run a test for each (given that you passed "ParseTest" as table name). Not knowing how you access the data from within your test I'd guess that the XML should like something like

<Test>
   <ParseTest>
      <uri>somestring</uri>
      <key>somestring</key>
      <value>somestring</value>
   </ParseTest>
   <ParseTest>
      <uri>somestring</uri>
      <key>somestring</key>
      <value>somestring</value>
   </ParseTest>
</Test>
Sign up to request clarification or add additional context in comments.

2 Comments

Your solution works, but the problem is now that the unit test does not end. It iterates trough every element and then is waiting. I cannot describe in what state MSTest is because the debug runs perfectly okay but after pressing F11 after the last line it just waits...
Was missing a Environment.Exit(). With Dependency Injection it now works...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.