This is a migrated thread and some comments may be shown as answers.

How to copy tests with coded steps in them?

3 Answers 280 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shane
Top achievements
Rank 1
Shane asked on 08 Jan 2013, 11:07 AM
Hi,

We are struggling to copy tests with coded steps in them.  After copying and pasting a test with a coded step it fails to compile due to "The namespace 'TestProject' already contains a definition for 'TestX'"

The reason why we are using copy and paste rather than execute test as step in Test Studio is due to the fact that our workflows require many variable test data columns ( some consist of over a thousand ) therefore we are splitting the test data up into smaller more manageable tables in the database, creating a test for this data and binding it to all rows, then when the QA staff copies this test they will open the data bind and select only the rows they want to use.

Is there any way around this or will I have to workaround it by either changing the namespace in the code each time or renaming the step and code behind the step making it impossible for QA ( who have no technical knowledge ) to re-use?

Thanks
Shane

EDIT: At the moment I have created a single test containing just the coded step to workaround the issue.  Although this works it seems strange to have to create tests every time I want to add a coded step. Please let me know if I have missed something.

3 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 08 Jan 2013, 01:18 PM
Hi Shane,
each test holds its coded steps in a class that bears its name. So for instance if you have TestX and you put a coded step into that - it will create a TestX.cs file to hold that coded step and any future coded steps. We call that one a code behind file. The code behind file holds a class that also has the same name as the test i.e.
public class TestX : BaseWebAiiTest

Now when you copy the test with a code behind file - the code behind file is also copied. Both files are renamed to TestX - Copy or something like that. But the class inside of the code behind file is not renamed and hence you get the error. And the only solution is to go in there and manually rename it so that it has the the new name:
public class TestX - Copy: BaseWebAiiTest

In Test Studio Standalone we take care of this for you. The problem only exists in the Visual Studio plug-in or when you're manually copying tests in the file system.

One way to get around this in Visual Studio is to create a new blank test and paste the existing steps from the old test in there. This will create an appropriately named code behind file.

I hope this helps. 

Regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Shane
Top achievements
Rank 1
answered on 08 Jan 2013, 02:32 PM
Hi Stoich,

Thanks for your initial response. That would be absolutely great if that were true ( which it is only if you copy and paste a test within the same folder ).  Unfortunately this is not ideal for us as we have a test in the location ..\TestProject\Templates\TestX.tstest which contains a coded step.  Now even in Test STudio Standalone, the QA engineer will be copying this test to another location e.g. ..\TestProject\Test1\TestX.tstest. This remains the same name and the class behind contains the same namespace and the same class name. So even using the Test Studio standalone it still remains an issue as the classname always appears to take the test name as its reference.

Also speaking about the using the VS plug-in I am also having problems with the names of the tests when copying.  It's probably something I'm doing wrong as it works fine in Test Studio Standalone. Whenever I copy a test using Solution Explorer in VS, then change the name of the test it does not change the code properties behind the test so if I have TestA.tstest which I then copy and paste and rename to  TestB.tstest the <Name> attribute still remains as TestA.tstest!!! This is causing problems for the QA Engineers when they receive the emailed report which must be taking it from this attribute rather than the actual test name as it displays the original test name as failed.

Thanks in advance
Shane
0
Stoich
Telerik team
answered on 11 Jan 2013, 01:40 PM
Hi,
might I suggest an alternative approach.

Why not put all the code into a single subtest (TestAsStep):
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/add-custom-step/test-as-step.aspx

This test can have multiple parent tests, each with unique data binding, calling the same subtest. Your subtest with the code can be set to InheritParentDataSource=true. You set that from the test settings:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/modifying-tests/test-properties.aspx

The parent tests are simply calling the single sub-test - no code is is actually located in the parent.

Taking this approach avoids the naming conflicts you are running into.


Regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Shane
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Shane
Top achievements
Rank 1
Share this question
or