Page 1 of 1

Start a testcase - pass name as parameter

Posted: Tue Sep 04, 2018 11:05 am
by jsmith
Hi there,
I want to start a test module via user code, but I want to reuse this method, so I want to pass the test module name in as a string, and have whatever that string is, run. My attempt so far is this:

public static void Run_a_test(string test_name)
{
string test_name = "Base_walkthru.Blocks.MSOfficeExport";
var execute = "Base_walkthru." + test_name;


//Base_walkthru.Blocks.MSOfficeExport.Start(); //correct implementation without parameterisation
execute.Start();
}


Unsurprisingly this doesn't work as the var needs casting to a module.
Can anyone advise how to go about this?

Re: Start a testcase - pass name as parameter

Posted: Tue Sep 04, 2018 11:34 am
by odklizec
Hi,

May I ask why do you want to run the test case via code? I mean, what's wrong with the test suite? I would personally use a combination of test suite and configurations, in which you can define what test cases should be run.

As far as I know, there is no public way to start the test case via code. All you can do is to start the test case via command line.

Re: Start a testcase - pass name as parameter

Posted: Tue Sep 04, 2018 12:49 pm
by jsmith
Hi Pavel,
My apologies, I have crossed two terms. I am trying to start a test module. Throughout many of my tests, I am repeating approx 100 lines of code, in this particular case, to test an export to MS Office feature. Recently I wanted to make a two line amendment to this section, and then need to roll it out across x number of uses. Instead, I have copied the 100 lines to a new test module. Now I need only change the code in one place, and call it in many places.
Hence, I have created the run_a _test user code method to execute any one test module. But I can see it would be useful to choose which module I want to run, without having to create another variation of run_a_test. Thus, I want a parameter, and to have the method start whatever test module I point it at.

I hope this helps clarify what I am trying to do, and I hope you can help me achieve it.

Re: Start a testcase - pass name as parameter

Posted: Tue Sep 04, 2018 1:17 pm
by odklizec
Hi,

I understand. But I'm afraid, this is not possible. The only thing you can probably do is to create a condition in your code module and then start the hardcoded module based of the condition? Something like this...

Code: Select all

public static void Run_a_test(string test_name)
{
  if (test_name == "AAA")
  {
    Base_walkthru.Blocks.ModuleA.Start(); 
  }
  else if (string test_name == "BBB")
  {
    Base_walkthru.Blocks.ModuleB.Start(); 
  }
}

Re: Start a testcase - pass name as parameter

Posted: Tue Sep 04, 2018 2:25 pm
by jsmith
Thank you Pavel, I shall use this approach.