<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.hoenzb
{mso-style-name:hoenzb;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-GB" link="blue" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi,</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This reply is to both you, Richard, and Daniel (didn’t want to pollute the list with two answers).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regarding 1:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’d worked out that I could wrap up the setup so it doesn’t blow and cleans up after itself if there’s an error, I’d just hoped that eunit could have done that for me by always running the cleanup function.</p>
<p class="MsoNormal">I like the idea of spawning the tests – I’ll try that in work tomorrow and see what happens.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I suppose the setup making sure that the system is in a known state before it starts is not a bad idea either but it may lead to lazy tests where no one cleans up after themselves.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Regarding 2:</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’ve written a quick test where the first two tests are not run because I’ve called an unknown function but the third test is run. As I say, the console does report the failing test but when we’ve got ~1000 tests that often produce debug
printouts this gets lost. I’ve noticed the “One or more tests were cancelled” – I don’t recall seeing that in work, I’ll check. However, we use intellij in work which doesn’t display the console results in the test runner by default.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-module(aborted).</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">-include_lib("eunit/include/eunit.hrl").</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">aborted_test_() -></p>
<p class="MsoNormal"> {</p>
<p class="MsoNormal"> foreach,</p>
<p class="MsoNormal"> fun setup/0,</p>
<p class="MsoNormal"> fun cleanup/1,</p>
<p class="MsoNormal"> [</p>
<p class="MsoNormal"> fun test1/1,</p>
<p class="MsoNormal"> fun test2/1</p>
<p class="MsoNormal"> ]</p>
<p class="MsoNormal"> }.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">setup() -></p>
<p class="MsoNormal"> state.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">cleanup(_State) -></p>
<p class="MsoNormal"> ok.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">test1(State) -></p>
<p class="MsoNormal"> call:unknown(State),</p>
<p class="MsoNormal"> [</p>
<p class="MsoNormal"> {"Passing test", ?_assertEqual(state, State)},</p>
<p class="MsoNormal"> {"First Failing test", ?_assertEqual(not_state, State)}</p>
<p class="MsoNormal"> ].</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">test2(State) -></p>
<p class="MsoNormal"> [</p>
<p class="MsoNormal"> {"Second Failing test", ?_assertEqual(really_not_state, State)}</p>
<p class="MsoNormal"> ].</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986">
Mail</a> for Windows 10</p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="border:none;padding:0cm"><b>From: </b><a href="mailto:carlsson.richard@gmail.com">Richard Carlsson</a><br>
<b>Sent: </b>16 July 2017 10:51<br>
<b>To: </b><a href="mailto:gareth.adams@outlook.com">Gareth Adams</a><br>
<b>Cc: </b><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<b>Subject: </b>Re: [erlang-questions] EUnit quirks</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1: A setup function is assumed to either succeed, with a possibly modified world as result, or fail, with an unchanged world as result. If you need to make multiple changes, the idea is that you either write separate setup/cleanup functions
for each change and nest them to create a complete setup, or you write a single setup function that does its own internal catching of errors and partial cleanup.
<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">2. All exceptions in a test case should be handled the same by eunit. Asserts are just one way of throwing an exception. Do you have an example to demonstrate what you are seeing?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"> /Richard<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">2017-07-14 18:45 GMT+02:00 Gareth Adams <<a href="mailto:gareth.adams@outlook.com" target="_blank">gareth.adams@outlook.com</a>>:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0cm;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt">Hi,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt">I've been writing some eunit tests using fixtures (<a href="http://erlang.org/doc/apps/eunit/chapter.html#Fixtures" target="_blank">http://erlang.org/doc/apps/eunit/chapter.html#Fixtures</a>) and have noticed
a couple of quirks.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt">1. If the setup fails for some reason cleanup is not called. This can be an issue if you're mecking things as the don't get unmecked so the next test setup fails etc. I find myself lost in a cascade of failures,
not knowing which tests are really failing.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt">2. If something fails in the test itself that's not part of an assert, eunit cancels the tests and they are not run. Although this is reported in the console, if you have a lot of tests with debug statements this
can be lost. The only thing that indicates that they've not been run is the number of tests decreases, which au not be noticed.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt">Has anyone else had these issues? If so, how did you handle them?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-left:14.4pt"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:14.4pt">
Thanks<span class="hoenzb"><span style="color:#888888"><o:p></o:p></span></span></p>
<div>
<p class="MsoNormal" style="margin-left:14.4pt"><span style="color:#888888">Gareth</span></p>
</div>
</div>
</div>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:14.4pt">
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><o:p></o:p></p>
</blockquote>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>