Unit Testing For Matlab



Hi all,

I've released my Matlab unit testing toolbox MUnit at

http://xtargets.com/cms/index.php?option=content&task=view&id=19

It is trivial to use and comes with a ( IMHO ) a very nice browser based control panel and browser based reporting of test results.

The control panel and test report allows you to

* Run tests.
* Debug tests.
* Open the editor to the exact line where a test error occured.
* See the full details of the assertion that failed.
* Create new test cases using a test generation wizard
* bookmark tests for easy access

The test file format is very simple and follows the standard unit test pattern of fixture setup and teardown with a number of tests. Using matlab nested functions this becomes extremely powerfull.

///////////////\\\\\\\\\\\\\\

function test = test_template

    % Subclass the testcase object
    test = munit_testcase;

    % Create a structure of constraint objects for assertions
    c = munit_constraint;

    function setup
        % This function will be called at the
        % start of *every* test_ function

    end

    function teardown
        % This function will be called at the
        % end of *every* test_ function
    end


% TEST_1 % % This is an example test. Create new tests by creating % new functions whose name starts with test_ function test_1

        % Assert that 1 == 1 to pass
        test.assert( c.eq( 1, 1 ) );

        % Assert that ~(1 == 1) to fail
        test.assert( c.not ( c.eq( 1, 1 ) ) );
    end
end

//////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\

See the tutorial and download at

http://xtargets.com/cms/index.php?option=content&task=view&id=19

Note this toolbox requires Matlab Service Pack 3 due to a few feature enhancements Mathworks made.

Happy testing

Brad









PS. There is a bonus toolbox which you must install which is a text templating engine I used to generate the HTML reports for MUnit. It can be used for any text based generation and is much like PHP or Velocity but uses the Matlab language. Use it to generate HTML, XML, C-Code, M-Code etc etc.

See
http://xtargets.com/cms/index.php?option=com_docman&task=cat_view&gid=10&Itemid=21


eg: ------------------------------------------

    # function mtemplate_usecase1(rows)
         <html>
             <body>
                # for i = 1:rows
                    <%=genline(i)%>
                # end
             </body>
         </html>

         # function genline(row)
             <p> <%= 1:row %> </p>
         # end

     #end

  -------------------------------------------


>> f = mtemplate_compile('mtemplate_usecase1.mt'); >> f(3) ans =

      <html>
          <body>
              <p> 1 </p>
              <p> 1  2 </p>
              <p> 1  2  3 </p>
          </body>
      </html>


( Note the license is GPL so if you use it in your own toolbox and distribute it you must also use a GPL license )


--
Brad Phelan
http://xtargets.com
.



Relevant Pages

  • Help integration Matlab >R13
    ... i am trying to integrate the help for my own toolbox into the Matlab help ... I allready wrote the info.xml and helptoc.xml to display the html ... help files in the help browser. ...
    (comp.soft-sys.matlab)
  • Re: Simple question ??
    ... A web page is basically an HTML document. ... a technology that, at the most basic level, delivers HTML to a web browser. ... Internet Explorer, for example, can display Word documents, ... file format to a browser in its native state. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Where is the notificiation about IE zero day vulnerablity?
    ... > protected your Firefox web client. ... > talking about how it was poised to be the one browser to finally ... some only the local news and others the weather. ... already reporting it - report the problem as well.. ...
    (microsoft.public.security)
  • Re: Toward WYSIWYG Web Page Authoring
    ... HTML and the web browser, ... Of course, even at the time of the first GUIs for developing HTML, WYSIWYG ... The best answer has emerged in the form of XML. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Mulberry gone, now what?
    ... > browsers is about reading broken HTML. ... It's easier for a browser to be backwards ... bear on web developers ("My son at college says the page looks different ...
    (comp.mail.imap)

Loading