Coded UI: Data Driven testing

In this one, I’m adapting the existing HTML test to allow tests to be driven from a xml file. The [TestMethod] attribute is pushed to the back of the new attribute set:

DataDrivenTest01

 

 

 

Here’s the bit that got chopped off:DataDrivenTest02and the code for this test.

The position of this TestData.xml in the solution:

DataDrivenTest03

 

And the content of TestData,xml:

DataDrivenTest04

The xml.

Run the test – we expect the 24,37 combination to be executed, then the -5,-2 combination. What actually happened was that the first one passed, but the second failed:

DataDrivenTest05

Why? Because the Page Object does not know how to handle the minus operator. The call:

DataDrivenTest06

… which calls…

DataDrivenTest07

That is crying out anyway for some refactoring of the Dom filtering, but that aside, let’s at least have a stab at handling signed integers… in fact forget it – I’ve just established that this web calculator is pretty broken when it comes to a deterministic way of handling negative signs (whereas the plus signs we can just throw away as the default). So I won’t waste any more energy on this one. What have I proven?

  • It’s easy to data drive in fact not just CodedUI tests, but any test that is a MSTest, and presumably a variation would work for other unit test frameworks.
  • Adding different data to the tests might reveal defects in the test itself… or in the Application Under Test, but maybe the AUT was designed / specced deliberately like that. I can’t know.

 

 

 

 

Advertisements