Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can unit tests be modular when they are dependant on other units?
    primarykey
    data
    text
    <p>I am trying to retrospectively unit test an application that is fairly complex but utilises MVC. I know retrospectively applying unit tests isn't ideal but I still believe it's possible by refactoring existing code. A majority of the time it is not possible to unit test one unit, without relying on other units i.e. a view relies on a model. </p> <p>What is the best way to unit test in this case? Is it better to utilise the real model or create a mock model?</p> <p>The problem with utilising a real model in my situation is that the model relies on other response classes that get data from XML so there's a chain of reliance. This model has a lot of data so it would be much easier to use this but maybe I'm missing the point.</p> <p>I have provided a UML of the application for brevity.</p> <p><img src="https://i.stack.imgur.com/mlw8C.jpg" alt="enter image description here"></p> <p>**Edit ****</p> <p>Ok so if I am correct, is it best practice to create mock data inside a mock class? for example I have the mock class "MockPlaylistPanelModel" that creates data required for the View class "PlaylistPanel" to run without errors:</p> <pre><code>class MockPlaylistPanelModel extends Mock implements IPlaylistPanelModel { /** * Return all playlist items * @public */ public function get mainPlaylistItems():Vector.&lt;PlaylistData&gt; { var playData:Vector.&lt;PlaylistData&gt; = new Vector.&lt;PlaylistData&gt;; var playlistResp:PlaylistData = new PlaylistData(0, "", "", 0, 0, 0, 0); playData.push(playlistResp); return playData; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload