During the verification and validation workflow, it is absolutely crucial to
test your component. You want to test your components to make sure that they
meet your requirements. So the first thing to do is to perform unit testing.
Unit testing consists in isolating your components, which we will call component
under tests, and then inject some test inputs. Test inputs can be injected
manually with dashboards or may be you can just use pre-recorded signals. The
same thing can be done to test the results. You can use dashboards or maybe
you can automate the process with some verifying assessments.
So let's see how this works in practice. So we go back to our Simulink model, we
go back to the state machine, and then from here what we need to do - we need to
go to the Simulink toolstrip, and then we need to create from here a test harness.
So to do this, we select Simulink test, and then after selecting Simulink test,
we can create a test harness by clicking on add test harness. We can give
a name to this test, we can specify location of the harness, and then we can
specify different ways to excite our system. We can use import we can use
signal builder, signal editor from word space and so on. So in this case we
select the signal builder and then same can be done for the outputs, so we can
select scope to workspace to files. In this case we select scope. So after doing
this we click on OK and this will automatically create the test harness
for us. So here you can see the signal builder, here you can see the model
reference which actually links to the component under test, and then here we
have the scope. So at this point we can make the model a bit more tidy, so we
select the components, we go to the format tab, and then we adjust the model
a little bit. So if you click on the signal builder, you will find out the
signals injected to the system and that you will need to either import or
manually modify. If you click on the badge on the bottom right you can come
back to the component under test, and the same can be done from the component
under test. You click on the badge and you can find
all the test harnesses that you have created. And in this way you can go back
and forth. Okay so I have previously created a test harness where I use
dashboards to manually test my component. So I select this harness and then from
here if I open this subsystem, I show different dashboard blocks that I can
use to manually test my component. So I run a simulation, and then from here I
can manually inject some test inputs. So I changed the cell
voltage to six, and then I can see that there is a fault given by the controller.
So when I stop the simulation, I could come back to the MATLAB workspace and I
can find a simulation output available. So this simulation output variable
contains the data set, which I'm now calling my faults scenario. And here you
can find all the signals that you have logged in the test harness - the path, the
name, and the values. So now we can perform another test so we go back to
the test harness, we go back to the dashboard subsystem, maybe we change back
to the same values before, we run the simulation, we change some other inputs,
and then we can see that now we are stimulating another fault. We stop the
simulation, we go back to the workspace, and then once again we get the data set.
We give it another name, and this is very important because now I can save these
datasets into a mat file, and this is very convenient because we can record
test inputs and then we can play them back. And this can be done for instance
if you create another test harness and you inject signals through another block,
which is a signal editor. so from the signal editor you can select the mat
file that contains all the data sets that you have recorded and indeed if you
open this block you can find all the data sets that you have previously
recorded, and they contain all the signals. Of course you can visualize
these signals to see what it looked like, but then you can even add other data
sets. So for example you can do duplicate one of the existing ones, you
can modify test inputs, you apply the modifications, and you can find that now
you have another test input. So after you do this, you can select any of the
scenarios that you have recorded and then you can run the simulations and
then you can verify the behavior of your component.