Frequently Asked Question

Video: 6.4.2 Complete automated test workflow
Last Updated 3 years ago


Press "Ctrl + F" to find the keyword of your interest.

If you wish to have a direct link access to the video timestamps, please follow these instructions.

Found this video helpful? Why not take the whole HIL Specialist course? A Certificate is waiting for you for free at HIL Academy.

Would you or your organization benefit from having these videos narrated in your native language? Contact us and let us know if you wish to contribute.

TRANSCRIPT

00:00:02

Hello and welcome to our second lesson on Typhoon Test.  

00:00:05

In this lesson, we will show how to write and automate a test using Typhoon Test. 

00:00:10

To perform this example, we will use the induction machine with vector control  

00:00:14

example. This model is a closed-loop speed control of an induction machine. 

00:00:20

First, let s save it in a different folder to build our tests without  

00:00:24

changing the library model file. Let s click on save as, navigate to the desired folder,  

00:00:33

and save it as model . After that, we can click on compile model, and we are ready to start. 

00:00:43

Once the compilation is complete, we can open TyphoonTest IDE from Typhoon HIL Control Center. 

00:00:52

In TyphoonTest IDE, you can select the environment, control your simulation with  

00:00:57

the start and stop button, select the working environment, write your tests,  

00:01:02

and much more. We will go through these functionalities throughout our course. 

00:01:06

Let s click on Create New File, Save Script,  

00:01:13

navigate to the folder where we have our model, and save it as test_speed . 

00:01:24

The software will ask if you want to change the working directory, so let s click on  

00:01:29

Yes , and select the same path where we saved the schematic and test file. This is used both  

00:01:34

as the reference path for the code and where the report will be generated and stored. 

00:01:38

On the left side, we have the API wizard tab, which is very similar to the one in SCADA. This  

00:01:44

will help us select functions and add them to our test. There is also the Structure  

00:01:49

tab that will help us write the tests.For our first test, let s check if it can  

00:01:56

track the motor speed reference. We can start by clicking on Add test. In the new window,  

00:02:01

we can write the test name as test_tracking , and a description such as:  

00:02:05

Testing speed tracking capability . Click OK. 

00:02:12

We can see that a code is added to the test file with the desired test name and description.  

00:02:17

You can also edit the code manually, like deleting the comment and pass lines. 

00:02:24

To load the schematics, we go to the API wizard tab, and in the field Add  

00:02:29

Module to list , we select HIL API and set the alias for this library as hil. 

00:02:37

Here you can see several modules you can import. You can look at these modules,  

00:02:41

and others, in our Documentation Hub in the Typhoon HIL Control Center. 

00:02:47

Here, we have documentation for HIL API, Schematic Editor API, SCADA API, and more. For example,  

00:02:55

if we open the Typhoon Test API you can see all the available functions. 

00:03:03

This documentation is also available on the web via the links provided in the Materials tab. 

00:03:09

Coming back to TyphoonTest, we can see some of these same functions under the hil alias.  

00:03:14

To begin with, let s search for load_model , and select it. 

00:03:22

Here, in the window below, we can read the documentation for this function.  

00:03:27

It is the same one from our Documentation Hub . In the last window,  

00:03:31

we have the wizard that will help us parametrize the functions. 

00:03:35

The first thing we need to do is load the schematic so that the wizard will  

00:03:38

know the available variables. So, click on Choose , and Load model at the top.  

00:03:44

Here, it is possible to select the .tse file as well as the .cpd file. If the .tse is selected,  

00:03:50

the model will be compiled. Since we already compiled our model, let s load the .cpd file. 

00:03:58

After loading it, the wizard recognized all the available variables from the model.  

00:04:03

Now, to load the model, let s click on File Picker , and then browse for  

00:04:08

the same .cpd file we just loaded, click on open , and finally hit Ok .  

00:04:19

This is going to fill out the value for the file argument. 

00:04:28

Since we will be running this using virtual HIL, we need to change the value of the  

00:04:32

vhil_device to True . After that, we place the cursor where we would like to insert the code,  

00:04:37

so let s click inside our function and click on insert function . 

00:04:44

Let s change the code so the model path is relative to the working directory. This way,  

00:04:49

it will not matter where you placed your files.The next command will be to start the simulation.  

00:05:00

So, let s search for start_simulation , select it, place the cursor and click on insert function . 

00:05:13

If we ran this example in SCADA , we would see that some variables are set at the beginning  

00:05:17

of the simulation, such as: speed reference, machine load, and the current reference for  

00:05:22

the direct axis. We need to do the same here.Let s start with the current reference value.  

00:05:28

As it is a SCADA input, we can search and select set_scada_input_value . In the line scadaInputName  

00:05:38

we click on choose , select SCADA inputs , and click on the green + sign. From the list  

00:05:44

of options, we select id_ref , and click on OK . In the line value we can type the value 0.2 and  

00:05:50

insert the code. Let's repeat this process to set the speed reference n_ref to 500 . 

00:06:03

Finally, to change the machine torque to a constant value,  

00:06:06

we can use machine_constant_torque function.  

00:06:14

For the name click on Choose , select Machines , press the + sign,  

00:06:18

and select the machine model name, indm .For the value, set it as 20. 

00:06:31

The next step is to wait for the simulation to reach a steady state.  

00:06:35

For that, we can use the wait function from the TyphoonTest Capture module.  

00:06:39

Let s add this module from the module list, set the alias to cap , and click on OK . 

00:06:50

Now we can search for wait , under the capture module,  

00:06:54

and click on it. Change the value to 1 and insert the function. 

00:07:09

Now we are ready to start the test capture. This will let us save signals  

00:07:13

for analysis after the test, just like the Scope/Capture widget in HIL SCADA. For this,  

00:07:18

we will be using the start_capture function. 

00:07:26

Let s set the duration to 1 second and the rate to 100e3 Hz.  

00:07:32

To select the signals, on the signals argument, click on choose , click on  

00:07:38

Signals , click on the green + sign to add new lines, and select n_meas , Ia , Ib , and Ic . 

00:07:51

Finally, click OK and insert the function.Now let s define a variable to delay our reference  

00:07:57

step change. So, let s define time_before_step = 0.1 and then use the wait function again calling  

00:08:05

this variable. We can do this either by using the wizard or typing it directly into the code. 

00:08:10

Now let s configure the speed reference step. First,  

00:08:14

let s create another variable n_ref and set it to 750. Let s change the speed reference,  

00:08:19

just like we did before, but now let s use the variable n_ref to set the new value. 

00:08:28

Finally, we can get the capture results. Since we want to use the capture data,  

00:08:32

let s attribute it to a variable. The captured data is returned as a Data Frame,  

00:08:37

from the Python module pandas , so let s call our data variable df . To obtain the capture  

00:08:43

data we use the get_capture_results function from the capture module. Let s set wait_capture to  

00:08:48

True , so the test will wait the full duration of the capture instead of interrupting it. 

00:08:58

Now we are able to analyze the signal. In order to do so,  

00:09:02

let s use a few functions from the TyphoonTest Signals module, here added with the sig alias. 

00:09:13

From here, we will be using pandas syntax. If you are not already familiar with it,  

00:09:18

you can check out the Python basics lessons earlier in this course. 

00:09:22

The first function we will be using is stepinfo , which will extract  

00:09:25

relevant information from a step response. 

00:09:34

As signal, let s select the measure speed, and change the settling time threshold to 1.  

00:09:39

Since we added a delay from the start of the capture until the change in reference, let s  

00:09:43

evaluate the step response from there, by changing evaluate_from_time to our delay variable. Finally,  

00:09:50

we can add a variable to save the returned value and insert this function to the code. 

00:09:59

Let s use the assert_is_step function from the  

00:10:01

signal module to check if the speed has the expected step response. 

00:10:11

For signal, select the measured speed. The step should happen at the delay time, from around  

00:10:16

500 to around the speed reference. So, let s set from_value as 495 to 505, to_value as the speed  

00:10:24

reference plus-minus 15, and at_t from the delay to the delay plus 200 milliseconds. Let s also  

00:10:30

change the strictness to 90%, allowing 10% of the signal to be outside of the allowed step region. 

00:10:55

We can also check if the measured speed is constant at the end of the capture.  

00:10:59

For that, let s use the assert_is_constant function. Here, let s set a smaller tolerance,  

00:11:04

of plus-minus 5 around the reference, and evaluate the signal from 900 milliseconds to 1 second. 

00:11:23

It is important to highlight that if the first assertion fails,  

00:11:27

Pytest will not run the second assertion. To overcome this behavior, we can use a Pytest  

00:11:32

plug-in called Pytest assume. This way, Pytest will run all assertions. If at least one fails,  

00:11:39

the test will fail. If all of them pass, the test will pass. In order to do this,  

00:11:44

we need to have each assertion inside a with pytest.assume statement. 

00:11:59

Finally, we can add the stop simulation command, and we will be ready to run the test file. 

00:12:11

To run the test, we can select among current file, working directory, and custom. The current  

00:12:18

file option will run this file we have open, the working directory will run all the tests  

00:12:22

that are available in this folder. In this case, both options will have the same effect.  

00:12:27

The custom option allows us to select the directory or the file that we want to run.  

00:12:32

We could also check the box select test by name , which is the -k option from Pytest, and  

00:12:35

the select test by mark which is similar to the -m option. 

00:12:45

Before we run the test, let s create a couple of errors in our code and see  

00:12:50

how that would look like. Let s add some characters to a library we are  

00:12:53

importing and change the variable time before step to time before . 

00:12:59

To run our test file, we select working directory and press the play button.  

00:13:04

If the option open report box is marked, it will automatically open the test report. 

00:13:14

As you can see, the report opened without any information. That is because there was an error  

00:13:19

while collecting the tests. In this case, go back to the TyphoonTest IDE console, where  

00:13:24

you can read the log and identify the error.Let s fix this error and run the test again. 

00:13:37

Now the test is yellow, indicating it is broken because there was an error during test execution.  

00:13:42

By opening the test, at the very top or bottom, we have the reason why it is broken.  

00:13:48

By clicking on it, we can see with more details and exactly where it is broken,  

00:13:52

making it much easier to identify errors. Let s also fix this one and run the test. 

00:14:14

After the test starts, we can check the Test Run and Console tabs.  

00:14:18

The Test Run tab shows all the collected tests, which test is running, the status  

00:14:22

of executed tests, the execution time for the setup, test, and teardown stages. The console  

00:14:29

shows a live log of what is happening during the test execution, so you can follow the procedure. 

00:14:35

So, let s check the Allure report. On the top left, we can see the number of test cases,  

00:14:42

the percentage of passing and failing tests, and the total testing time. 

00:14:50

You can click on each test in the Suites section to look for more details. 

00:14:56

Here, all the API functions are shown in the report.  

00:15:00

We can see the simulation time of this specific test, its description, and the time of each step. 

00:15:08

The first step was to load the model, start the simulation, set the value for id_ref , torque, and  

00:15:14

speed. After that, we waited 1 second and started the capture, changed the speed reference, and got  

00:15:21

the capture results after the defined duration. The API function automatically added the images  

00:15:26

from the capture for all the selected signals, in this case Ia , Ib , Ic , and the measured speed. 

00:15:35

Now let s check the step info, where we have the rising time, undershoot, overshoot,  

00:15:40

settling time, ripple, and more. Here you can see the results either in the image or  

00:15:45

numerically, by expanding the Results .Finally, we have the assertion functions,  

00:15:56

where you can expand them and take a better look at the results. 

00:16:09

Now we have a working test and can use it to test many more cases. We can parametrize the test to  

00:16:15

check the performance of several operating conditions and optimize its execution by  

00:16:19

migrating some portions of the test to a fixture. First, place your cursor on top of the function,  

00:16:25

so the fixture will be placed at the top. Select the tab structure , click  

00:16:30

on add fixture , change the name to load model , select the scope as module , and click on ok . 

00:16:42

After that, let s cut and paste the code for loading model,  

00:16:45

starting the simulation, and initial parameterization into the fixture setup.  

00:16:50

Also, let s move stop simulation to the fixture teardown. 

00:16:59

Now, let's add another fixture to return the speed to a default value.  

00:17:04

Click on add fixture , change the name to return_to_500 , leave the scope as  

00:17:08

function , add the load_model fixture in the fixture field, and click on ok . 

00:17:19

Let s move the code for returning the speed of the system to the initial condition to the fixture. 

00:17:33

Now we can parametrize this test for different speeds and loads, so let s select test_tracking  

00:17:38

and click on edit . In the new window, we need to add the fixture return_to_500 . Now  

00:17:43

we can parametrize the fixture. There are a couple of options to parametrize the test,  

00:17:49

so in this first demonstration we will use tables. Let s say we want to test four different  

00:17:53

speeds. Let s add two columns and four rows. Let s rename the columns to n_ref , with values 750,  

00:18:01

750, 1000, and 1000 and the other column to load with values 10, 30, 10, and 30. After that,  

00:18:10

we click on ok and it will update the test with all the test cases we would like to test. 

00:18:22

After that, we need to delete the hard coded speed reference,  

00:18:25

and edit the machine torque with the provided load . 

00:18:39

A different way to parametrize the test is by adding the speed and load parametrization  

00:18:43

individually. This second approach is more suited when you want to test all combinations  

00:18:48

from different variable arrays. Just keep in mind that as we covered in the Pytest Basics lessons,  

00:18:54

the parametrization order changes the test execution order, which may in turn affect  

00:18:59

your test results.After that,  

00:19:06

we are ready to run the test again, so let s press the play button. 

00:19:20

Let s take a look at the results, for all four test cases. As expected,  

00:19:25

the first test has a longer setup, since it is loading the model with a module scope fixture.  

00:19:31

Thus, the setup times of the other tests are close to zero. It is also possible to see that  

00:19:36

most of the time was spent on test execution, with close to zero time spent on teardown. 

00:19:43

If we open the test report, we can see that one of the tests passes and the others failed.  

00:19:48

Let s take a closer look at the first test that failed. 

00:19:54

At the top, you can see the reason why the test failed.  

00:19:57

Here, it did not comply with the 90% tolerance, since the signal stayed inside  

00:20:02

the allowed region for only 79% of the time. By clicking on it, we can see more details. 

00:20:11

In the parameters section, we can verify the parameters used for this test case. 

00:20:17

Also, we can check the Set up stage, where we have the setup of all the fixtures used by the test.  

00:20:23

Here, we see loading the model and returning the system to the default values. 

00:20:28

Just as before, we can look the test results in more details by navigating though the report. 

00:20:38

In this lesson we learned how to run tests with the HIL and to  

00:20:41

optimize tests using fixtures and parametrization.  

00:20:44

In the next lesson, we will enhance this test by adding more signal analyses to it.

Please Wait!

Please wait... it will take a second!