Skip to end of metadata
Go to start of metadata

What are the Contexts? 

In testing it is important to ensure that each test case is executed in a certain environment and while your AUT is in a certain state. For instance, your test requires some projects/files presenting in your workspace, certain views/editors should be open and preferences set or, on the contrary, you need a clear start after all previous operations. Obviously, most of the time it is technically possible to include preparation logic into your test code, but this method has numerous disadvantages:

  1. It is hard to maintain changes
  2. It increases the test size and the amount of your written code in general
  3. It makes it harder to understand the purpose of your test
  4. There is no way in which you can reuse similar code pieces except for Copy/Paste

In order to keep your tests small and efficient, Q7 provides an effective tool to address these issues: Q7 Contexts. Instead of using manual setup for your workspace content, workbench layout and preferences configuration preceding your tests, you can assign corresponding reusable contexts to each test case to ensure that the Application Under Test is brought to a certain state every time you start testing.

Contexts are also a key part of one of Q7 fundamental principles: your tests should be independent. With a help of Contexts every time you run a test case, Q7 reinstates its specific environment so that other tests, whether failed or not, would not affect its result.

How do I create a Context?

You can use the New Context Wizard to create a new Context in your Q7 project. The wizard can be opened directly from the File > New > Context menu item or with the right-click menu in Q7 Explorer.


At this step you simply choose the Context type (Workspace, Workbench, etc), the Context name and the project that contains your new Context. Please note that later you can use this Context in another project if proper references are set.

As soon as you click the Finish button, the Context appears on your Q7 workspace in the project it is assigned to.

You can now edit your Context in the Test Editor along with your test cases. 

The content of your Editor window depends on the type of the selected Context. You can read more on the Context types below.

What are the Context types?

There are several types of Contexts available at the moment:

Workspace Contexts
Workbench Contexts
Preferences Contexts
Group Contexts
ECL Script Contexts
Debug Contexts

How do I add a Context to my test case?

You can add a Context in two ways:

1. When you record your new/existing test case, switch to the Context tab in the Q7 Control Panel window.

You can press the green "plus" icon to open the Select Context dialog. You now have three options:

  • choose an existing Context from the list
  • create a new Context with the New Context Wizard (Select Context > New...) and select your newly created Context from the list
  • create a new Context by capturing your current state (Select Context > Capture...) and select your newly created Context from the list

The Capture option is available for Workspace, Workbench and Preferences contexts.

You can also select several contexts at once by using Ctrl or Shift buttons.

When the "Show only contexs from the requied projects" option is checked, the list will only contain contexts from the linked projects.

If you add a Context from a project that has no references from the current one, the dialog opens where you can add proper references:

Otherwise, the Context would appear in the context list as 'unresolved'.

2. In the Test Editor, while editing an existing test case, you can unfold the Context panel and select an existing Context from the list by pressing the green "plus" icon or create a new one.

You can also Copy/Paste your Contexts from Q7 Explorer and/or one test case to another or use the Drag-and-Drop feature.

When several contexts are assigned to your test case, they will be applied in the corresponding order.

 

Next step: Work with Tags

Labels: