Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Mock objects and unit testing

Subject: Mock objects and unit testing

From: Terral

Date: 10 Feb, 2009 20:40:04

Message: 1 of 7

, I'm trying to write unit tests for my MATLAB code base. I've written a fair number of classes, and I have a number of them set up with unit tests using mlunit. Unfortunately, it's come time to try and test some of the the inner parts of my object graph, and to try to minimize the dependency of these tests on other objects, I want to mock out some of the objects.

Unfortunately, it appears the MATLAB does not support private classes. Ideally, I'd be able to write these classes into the same files as the tests I'm writing, since they're (by definition) going to be barebones. Has anybody else done this? If so, how did you do your mocks?

Subject: Mock objects and unit testing

From: Michael

Date: 15 Feb, 2013 19:52:16

Message: 2 of 7

I would like to be able to do the same thing. Did you perhaps discover a way to do this?

Subject: Mock objects and unit testing

From: Michael

Date: 15 Feb, 2013 19:54:13

Message: 3 of 7

I would like to do the same thing. Did you perhaps discover a way to do this?

Subject: Mock objects and unit testing

From: Andy Campbell

Date: 18 Mar, 2013 14:23:03

Message: 4 of 7

On 2/15/13 2:52 PM, Michael wrote:
> I would like to be able to do the same thing. Did you perhaps discover a
> way to do this?


R2013a now includes a full unit test framework:

https://www.mathworks.com/help/matlab/matlab-unit-test-framework.html

Subject: Mock objects and unit testing

From: per isakson

Date: 22 Mar, 2013 03:09:06

Message: 5 of 7

Andy Campbell <Andy.Campbell@mathworks.com> wrote in message <ki7807$97m$1@newscl01ah.mathworks.com>...
> On 2/15/13 2:52 PM, Michael wrote:
> > I would like to be able to do the same thing. Did you perhaps discover a
> > way to do this?
>
>
> R2013a now includes a full unit test framework:
>
> https://www.mathworks.com/help/matlab/matlab-unit-test-framework.html

Yes, but not a word about mocks or other fake objects - as far as I can see.

Subject: Mock objects and unit testing

From: daniel.jara.heredia@gmail.com

Date: 16 Apr, 2014 15:09:56

Message: 6 of 7

On Friday, March 22, 2013 4:09:06 AM UTC+1, per isakson wrote:
> Andy Campbell <Andy.Campbell@mathworks.com> wrote in message <ki7807$97m$1@newscl01ah.mathworks.com>...
>
> > On 2/15/13 2:52 PM, Michael wrote:
>
> > > I would like to be able to do the same thing. Did you perhaps discover a
>
> > > way to do this?
>
> >
>
> >
>
> > R2013a now includes a full unit test framework:
>
> >
>
> > https://www.mathworks.com/help/matlab/matlab-unit-test-framework.html
>
>
>
> Yes, but not a word about mocks or other fake objects - as far as I can see.

Did you find a solution for this problem?

Subject: Mock objects and unit testing

From: daniel.jara.heredia@gmail.com

Date: 23 Apr, 2014 15:26:10

Message: 7 of 7

On Tuesday, February 10, 2009 9:40:04 PM UTC+1, Terral wrote:
> , I'm trying to write unit tests for my MATLAB code base. I've written a fair number of classes, and I have a number of them set up with unit tests using mlunit. Unfortunately, it's come time to try and test some of the the inner parts of my object graph, and to try to minimize the dependency of these tests on other objects, I want to mock out some of the objects.
>
> Unfortunately, it appears the MATLAB does not support private classes. Ideally, I'd be able to write these classes into the same files as the tests I'm writing, since they're (by definition) going to be barebones. Has anybody else done this? If so, how did you do your mocks?

to do a mock class, what I do is to create a function of the MOCK class that I want to test. This function will be call in properties (Constant) of the test class.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us