Code Items

Code Items are standalone code files that allow you to create coded logic that is not bound to a specific test case.

A code item can be useful for creating a utility class that defines a set of methods which perform common, often re-used functions. The code item can be used also as a helper class which can assist in providing some extended functionality for your test project.

How to Create a Code Item

Right click on the project in the Project Explorer or on a folder in the project and click on Add Code Item.

Add Code Item

Choose a name for the new code item and click OK (RandomUsenameGenerator in this example)

Set Code Item Name

The Code Item with name RandomUsenameGenerator is created under the selected location (under the Utilities folder in this example)

Code Item in Project Explorer

How to Use a Code Item

This is an example on how to use a code item.

Open an already created code item (RandomUsenameGenerator in this example) and add a public method that accepts a string for baseName, appends a random suffix to it and returns it as a randomized username (this could be used for tests that need to create a new test user with unique username).

Code Item Example

In order to access the code item's properties and methods in a test's code-behind file, you should add a using statement in the code-behind which matches the namespace of the code item (DemoTests.Utilities in this example).

Using a Code Item

See Also

In this article
Not finding the help you need? Improve this article