-2

I Have a desktop Application in which I have 200 Test cases with different input parameters

Now the issue is Every time I am recording the Each and every test case with different input parameters

Is there is any way so that I can copy the code and change the parameters so that my code remains same for all the test cases only input parameters change

Rajesh Akshith
  • 301
  • 3
  • 14
  • I'd like to know who is going around down voting the coded ui questions and not leaving any comment as to why... – MPavlak May 31 '16 at 19:44

2 Answers2

1

There are a few things to address here. Firstly, you can run the test using a data driven approach as described in the link above.

More importantly, in my opinion anyway, is how you are writing your test so that they can be data driven and what exactly are you testing that you need so many combinations?

When writing tests, it is important to have reusable code to test. I would recommend looking at something like Code First Scaffolding or Coded UI Page Modeling (I wrote the page modeling stuff). With these approaches, your test code is far more maintainable and flexible (easier to change by hand). This would allow for extremely simple data driven tests.

public void WhenPerformingCalculation_ThenResultIsCorrect() {
    // imagine calculator with two numbers and a sign
    var testResult =
    modelUnderTest.LeftSideNumber.SetValue(3) // set first number
                  .Operator.SetValue("*") // set sign
                  .RightSideNumber.SetValue(10) // set right number
                  .Evaluate.Click() // press evaluate button
                  .Result; // get the result
    Assert.AreEqual(testResult, 30);
}

becomes

public class CalculationParameters
{
    public double LeftNumber {get;set;}
    public string Operator {get;set;}
    public double RightNumber {get;set;}
    public double Result {get;set;}
    public override string ToString(){ return $"{LeftNumber} {Operator} {RightNumber} = {Result}"; }
}

public void WhenPerformingCalculation_ThenResultIsCorrect() {
    ICollection<CalculationParameters> parameters = getParameters();

    List<Exception> exceptions = new List<Exception>();
    foreach(CalculationParameters parameter in parameters)
    {
        try
        {
            var testResult =
            modelUnderTest.LeftSideNumber.SetValue(parameter.LeftNumber) // set first number
                          .Operator.SetValue(parameter.Operator) // set sign
                          .RightSideNumber.SetValue(parameter.RightNumber) // set right number
                          .Evaluate.Click() // press evaluate button
                          .Result; // get the result
            Assert.AreEqual(testResult, parameter.Result);
        }
        catch (Exception e)
        {
           exceptions.Add(new Exception($"Failed for parameters: {parameter}", e));
        }
    }
    if(exceptions.Any()){
        throw new AggregateException(exceptions);
    }
}

Secondly, why do you need to test so many combinations of input / output in a given test? If you are testing things like, "Given the login page, when supplying invalid credentials, then a warning is supplied to the user." How many invalid inputs do you really need to test? There would be a second test for valid credentials and no data driving is necessary.

I would caution you to be careful that you are not testing stuff that should be a unit test in your UI. It sounds like you are testing different combinations of inputs to see if the UI generates the correct output, which should probably be a unit test of your underlying system. When testing the UI, typically it is sufficient to test that the bindings to your view models are correct and not test that calculations or other server logic is performed accurately.

My provided example shows what I would NOT test client side unless that calculator only exists client side (no server side validation or logic regarding the calculation). Even in that case, I would probably get a javascript test runner to test the view model powering my calculator instead of using coded ui to do this test.

Would you be able to provide some example of the combinations of input/output you are testing?

Community
  • 1
  • 1
MPavlak
  • 2,133
  • 1
  • 23
  • 38
0

You can use the event arguments to the application through command line with a batch script or you can create a function what will pass the requested parameters. In the main header you can use main(string eventargs[]);

where the string variable will be the event arguments from the command line

Shon
  • 486
  • 4
  • 9