{"id":4503,"date":"2015-04-11T07:56:50","date_gmt":"2015-04-11T12:56:50","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=4503"},"modified":"2015-04-11T07:56:50","modified_gmt":"2015-04-11T12:56:50","slug":"creating-test-harnesses-with-simulink-test","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2015\/04\/11\/creating-test-harnesses-with-simulink-test\/","title":{"rendered":"Creating Test Harnesses with Simulink Test!"},"content":{"rendered":"<p>In R2015a, we introduced a new product called <a href=\"https:\/\/www.mathworks.com\/products\/simulink-test\/\">Simulink Test<\/a>. This product offers many great features like a <a href=\"https:\/\/www.mathworks.com\/help\/sltest\/ref\/testsequence.html\">Test Sequence<\/a> block, various ways to test results of a model against validated data, and a <a href=\"https:\/\/www.mathworks.com\/help\/sltest\/ug\/introduction-to-the-test-manager.html\">test manager interface<\/a>.<\/p>\r\n\r\n<p>Among all the feature of Simulink Test, the one that I am the most interested in is the Test Harness. I think this will make developing and debugging models more efficient. Let's see how this works.<\/p>\r\n\r\n<p><strong>What is a Test Harness?<\/strong><\/p>\r\n\r\n<p>Let's say I am developing or debugging a model with multiple components. To illustrate the harness concept, we will use an example model I like: <a title=\"https:\/\/www.mathworks.com\/help\/stateflow\/examples\/modeling-a-pwm-driven-hydraulic-servomechanism.html (link no longer works)\">sf_electrohydraulics<\/a>. This example is great because it contains multiple components of various domains: electrical, hydraulics, mechanical, etc.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/sf_electrohydraulics.png\" alt=\"sf_electrohydraulic\" \/><\/p>\r\n\r\n<p>Before R2015a, when a model like this one was giving me unexpected results, what I ended up doing is pasting the component I suspected to be problematic in a new empty model and feed it known inputs to see if I get the output I expect.<\/p>\r\n\r\n<p>With the Simulink Test Test Harness feature, this test or debug model can now be part of the original model, making it very easy to manage (no additional files), and to switch between the large model and the test harness.<\/p>\r\n\r\n<p><strong>Creating a Harness<\/strong><\/p>\r\n\r\n<p>To get started, right-click on a subsystem and select <strong>Create Test Harness<\/strong>:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/createTest.png\" alt=\"Creating a Test Harness\" \/><\/p>\r\n\r\n<p>A dialog will open where you can set the properties of the harness. When the harness is created, it can be created with standard blocks like Inport, Signal Builder, From Workspace, etc.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/createTestDialog1.png\" alt=\"Creating a Test Harness\" \/><\/p>\r\n\r\n<p>Then you select the harness objective.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/harnessObjective.png\" alt=\"Creating a Test Harness\" \/><\/p>\r\n\r\n<p>What is the meaning of those objective?<\/p>\r\n\r\n<ul>\r\n\t<li><strong>Prototyping:<\/strong> If your original model does not compile, that's what you need. The harness will be created without knowledge of input\/output signals properties like dimensions and data type. This should allow you to debug and figure out why the original model does not update.<\/li>\r\n\t<li><strong>Refinement\/Debugging:<\/strong> In this case, the original model will be compiled and blocks will be inserted in the harness to ensure the input and output signals have the same properties, dimensions, data types, etc.<\/li>\r\n\t<li><strong>Verification:<\/strong> In the harness, the subsystem will be marked as read-only so it can be validated, but not modified. In addition, SIL and PIL mode verification options are enabled for the component under test. The harness is also rebuilt each time it is opened so that the compiled attributes enforced in the harness are re-computed from the main model and brought up-to-date.<\/li>\r\n\t<li><strong>Custom:<\/strong> Four independent checkboxes will be enabled for you to combine the properties of the three above ojectives the way you want.<\/li>\r\n<\/ul>\r\n\r\n<p>When you click <strong>OK<\/strong> the test harness opens.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/exampleHarness.png\" alt=\"Creating a Test Harness\" \/><\/p>\r\n\r\n<p><strong>Navigating Between the Harnesses and the Model<\/strong><\/p>\r\n\r\n<p>When a subsystem has harnesses, you will notice a new icon on its bottom right corner. Clicking on it will list the harnesses.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/harnessInModel.png\" alt=\"Opening a Test Harness\" \/><\/p>\r\n\r\n<p>To avoid confusions, you can open only one harness at a time and the original model cannot be edited when a harness is open. In the harness, you can modify the subsystem as you wish, and the changes will be propagated to the original model as soon as you close the harness.<\/p>\r\n\r\n<p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>Do you think the Test Harness feature will be useful for you? Let us know how you plan to use it by leaving a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=4503&#comment\">comment here<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2015Q1\/harnessInModel.png\" onError=\"this.style.display ='none';\" \/><\/div><p>In R2015a, we introduced a new product called Simulink Test. This product offers many great features like a Test Sequence block, various ways to test results of a model against validated data, and a... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2015\/04\/11\/creating-test-harnesses-with-simulink-test\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[121,63,16],"tags":[425,424],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/4503"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=4503"}],"version-history":[{"count":18,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/4503\/revisions"}],"predecessor-version":[{"id":4567,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/4503\/revisions\/4567"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=4503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=4503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=4503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}