Script-Based Unit Testing Problem (from MathWorks example)

Hello,
I copied and pasted the Script-Based Unit Testing Example from MathWorks http://www.mathworks.com/help/matlab/matlab_prog/write-script-based-unit-tests.html?refresh=true, but I am encountering an error. All of the tests fail because the variables in the shared variable section are not properly defined. From my understanding of the example, the variables in this section should be defined globally and can be used for any of the four tests in the example. However, there is obviously some error here.
Here's an example of the error:
Uncaught error occurred in rightTriTolTest/Test1_SumOfAngles. The remainder of the test method will not run to completion.
--------------
Error Details:
--------------
Undefined function or variable 'tri'.
I have tried creating the variables in the workspace before running the tests, but that did that work either. I also am running on R2014a, not sure if there were any changes in 2015.
Please let me know of any suggestions, I have followed the example exactly as shown in the link (copy+pasted)

 Réponse acceptée

Andy Campbell
Andy Campbell le 11 Juin 2015
Hello,
The Script based testing interface was added in R2014b, and in that release the shared variable section was not supported. The shared variable section feature was added in R2015a.
However, the error message you got confuses me. While the shared variable section was not supported in R2014b, we were indeed looking into it and to prevent incompatibility creating a test suite from a script which utilizes the shared variable section at all should have been an error when creating the test suite.
Can you provide details of your version, the script you are running and how you are trying to run it?
Thanks, Andy

5 commentaires

Andy Campbell
Andy Campbell le 11 Juin 2015
Modifié(e) : Andy Campbell le 11 Juin 2015
Nevermind, what you are seeing is expected. Basically the crux is that the script based testing feature was included with the framework in R2014a but not documented because it wasn't ready for production yet. The fact that you can use runtests on a script at all in R2014a is not documented and not formally part of MATLAB.
In R2014b we did the needed work to make it documented (i.e. like erroring in the shared variable section if defined to prevent incompatibility) and then in R2015a the shared variable section was documented and fully supported.
Sure, here's the ver output:
>> ver ---------------------------------------------------------------------------------------------------- MATLAB Version: 8.3.0.532 (R2014a) MATLAB License Number: •••••• Operating System: Microsoft Windows 7 Home Premium Version 6.1 (Build 7601: Service Pack 1) Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot™ 64-Bit Server VM mixed mode ---------------------------------------------------------------------------------------------------- MATLAB Version 8.3 (R2014a) Simulink Version 8.3 (R2014a) Aerospace Blockset Version 3.13 (R2014a) Aerospace Toolbox Version 2.13 (R2014a) Bioinformatics Toolbox Version 4.4 (R2014a) Control System Toolbox Version 9.7 (R2014a) Curve Fitting Toolbox Version 3.4.1 (R2014a) DSP System Toolbox Version 8.6 (R2014a) Data Acquisition Toolbox Version 3.5 (R2014a) Image Processing Toolbox Version 9.0 (R2014a) Instrument Control Toolbox Version 3.5 (R2014a) Optimization Toolbox Version 7.0 (R2014a) Parallel Computing Toolbox Version 6.4 (R2014a) Signal Processing Toolbox Version 6.21 (R2014a) SimMechanics Version 4.4 (R2014a) Simscape Version 3.11 (R2014a) Simulink Control Design Version 4.0 (R2014a) Stateflow Version 8.3 (R2014a) Statistics Toolbox Version 9.0 (R2014a) Symbolic Math Toolbox Version 6.0 (R2014a)
I can copy the scripts if you like, but I have been running them exactly as shown in the MathWorks example (copied + pasted several times to make sure I didn't miss anything). Here's the command I use to run the test:
>> result = runtests('rightTriTolTest')
Andy Campbell
Andy Campbell le 11 Juin 2015
Modifié(e) : Andy Campbell le 11 Juin 2015
Yeah, I see the issue here as described in my first comment above, which is we have a doc version mismatch. If you look at the documentation in your MATLAB (rather than the website which is the doc for R2015a) you should actually not see anything about script based testing at all.
Ah, ok. Thanks! Do you know if there's any similar documentation on that type of unit testing for R2014a? I'm trying to fix my R2015 (having graphics problems.. different story), but it would be good to practice on the older version for now.
Well its not supported in R2014a at all, so you are in uncharted waters.
Your mileage may vary with the R2014b doc, which is the first release it was officially supported:

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by