Comments on: Using the MATLAB Unit Testing Infrastructure for Grading Assignments https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/?s_tid=feedtopost Loren Shure is interested in the design of the MATLAB language. She is an application engineer and writes here about MATLAB programming and related topics. Mon, 01 Aug 2016 01:51:23 +0000 hourly 1 https://wordpress.org/?v=6.2.2 By: David Hruska https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-36087 Tue, 02 Apr 2013 14:14:15 +0000 https://blogs.mathworks.com/loren/?p=649#comment-36087 @David: Unfortunately, the MATLAB language doesn’t currently provide a way to programmatically terminate execution of code after a certain period of time. I’ve submitted this suggestion as an enhancement request.

]]>
By: David https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-36078 Tue, 02 Apr 2013 05:23:08 +0000 https://blogs.mathworks.com/loren/?p=649#comment-36078 Is there a way to include a timeout for this kind of unit testing? For example, if the student includes an infinite while loop, is there a way to automatically fail the test case after 5 seconds?

]]>
By: Eric https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-35953 Tue, 26 Mar 2013 19:47:48 +0000 https://blogs.mathworks.com/loren/?p=649#comment-35953 Thanks, that info could be handy to add to the doc if it isn’t there already. Cheers

]]>
By: David Hruska https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-35868 Fri, 22 Mar 2013 12:02:30 +0000 https://blogs.mathworks.com/loren/?p=649#comment-35868 Eric: yes, setup and teardown are handled in an exception-safe manner so even if the test execution is terminated for some reason, the teardown routines will still execute.

]]>
By: Andy Campbell https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-35859 Fri, 22 Mar 2013 02:03:46 +0000 https://blogs.mathworks.com/loren/?p=649#comment-35859 Hi Eric,

Yes, the code defined in the teardown methods executes in an exception safe way.

There is also another feature that allows adding teardown code dynamically and executes in a deterministic order (Last-In-First-Out, or LIFO). Look here for more information:

https://www.mathworks.com/help/matlab/ref/matlab.unittest.testcase.addteardown.html

]]>
By: Eric https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-35852 Thu, 21 Mar 2013 19:24:23 +0000 https://blogs.mathworks.com/loren/?p=649#comment-35852 Do the TearDown methods execute even if the test code errors out or the user Ctrl-C’s (like an onCleanup)?

]]>
By: Andy Campbell https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-35730 Sat, 16 Mar 2013 12:38:35 +0000 https://blogs.mathworks.com/loren/?p=649#comment-35730 Hi Capitan,

Thanks for taking a look at the framework!

I understand your preference for limiting the verbosity. For this interface we have weighed the simplicity of naming conventions against the robustness and flexibility of defining them with explicit constructs. We have landed on the latter approach. This has a number of benefits including:

* Decoupling the name of a method from how the method is intended to be used by the framework.

* Enabling using test base classes that set up fixtures needed for the base class and all subclasses. With this interface there is no need to override the “setUp” method in a subclass and remember to call through to the base class setUp method. Rather, the base class can simply define its own fixture method(s), even making them Sealed so they cannot be overridden, and the subclass can create its own independent method for the portion of the setUp needed by the subclass.

* Allowing more familiarity with the more modern xUnit implementations such as JUnit 4 (rather than JUnit 3) and NUnit which have evolved away from naming convention and toward annotation/attribute style approaches.

* Preventing the enforcement of a naming convention. I am all for “convention over configuration” approaches, but this requires that there be some way to opt out of the convention if desired. However, relying so explicitly on the naming convention by the framework precludes the ability for someone to choose not to adhere, or perhaps choose a *different* naming convention to fit inside their organizational guidelines. We felt the decision of what to name methods and classes should not be ours but rather the test writer using the interface, and this approach supports that.

* Logically grouping methods by their purpose. While it is indeed more verbose, there is a benefit in separating the “TestMethodSetup” methods from the “Test” methods from even the normal helper methods that are not used directly by the framework. Keeping them separated into their own methods blocks tends to keep code similar in function close to one another, having a side benefits of actually making it easier to find the method of interest at times.

Anyway, thank you again for taking a look and I encourage you to take a closer look at many other benefits and features in this new framework including:
* The rich library of qualification (assertion) methods available
* The ability to create fixtures that are shared between all the methods of a test class
* The increased diagnostics infrastructure which does a better job of describing the problem encountered when a failure occurs
* The full support of the framework by The MathWorks
* The knowledge that tests can be written that can be run and shared with colleagues without any additional download or setup as long as they have R2013a or later.

…and please if you do continue to evaluate it, keep the feedback coming!

Thanks,
Andy

]]>
By: capitan.cambio https://blogs.mathworks.com/loren/2013/03/14/using-the-matlab-unit-testing-infrastructure-for-grading-assignments/#comment-35715 Fri, 15 Mar 2013 20:59:38 +0000 https://blogs.mathworks.com/loren/?p=649#comment-35715 I think it’s fantastic that matlab has its own built-in xUnit framework.

I do quite a bit of matlab OO programming in a daily basis, and one of the most exasperating issues is the verbosity of the matlab language in these matters (i.e. property block, static methods block, regular methods block …).

In the documentation of the new framework explains that in order to define the setUp and tearDown methods the actual code should be like:

methods(TestMethodSetup)
function createFigure(testCase)
%comment
testCase.TestFigure = figure;
end
end

whereas in the framework linked suffices a method called setUp(self) and it is execute on a name convection basis. Less code to write, less time to actually solve the problem.

Anyway, it is a good thing have a built-in support for unit testing.

]]>