<div dir="ltr">2013/11/8 Manlio Perillo <span dir="ltr"><<a href="mailto:manlio.perillo@gmail.com" target="_blank">manlio.perillo@gmail.com</a>></span><br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
Allora no, che io sappia nose ed PyUnit non si comportano come le nuove versioni di JUnit.<br>
<br></blockquote><div><br></div><div>Capito.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Puoi postare un esempio di come si fa in JUnit?<br></blockquote><div><br></div><div>Ecco qua.</div><div><br></div><div>******** SuperTest.java ******** </div><div>import org.junit.Before;</div><div>import org.junit.Test;</div>
<div><br></div><div>public abstract class SuperTest {</div><div> @Before public void init() throws Exception {</div><div> System.out.println("I'm a Super init");</div><div> }</div><div> @Before public void anotherInit() throws Exception {</div>
<div> System.out.println("I'm another Super init");</div><div> }</div><div><br></div><div> @Test public void just_a_test() throws Exception {</div><div> System.out.println("Just a test in the superclass");</div>
<div> }</div><div> @Test public void yet_another_test() throws Exception {</div><div> System.out.println("Yet another test in the superclass");</div><div> }</div><div>}</div><div><br></div><div><br></div>
<div><br></div><div>******** Subest.java ******** </div><div>import org.junit.Before;</div><div>import org.junit.Test;</div><div><br></div><div>public class SubTest extends SuperTest {</div><div> @Before public void subInit() throws Exception {</div>
<div> System.out.println("I'm a Sub init");</div><div> }</div><div> @Before public void anotherSubInit() throws Exception {</div><div> System.out.println("I'm another Sub init");</div>
<div> }</div><div><br></div><div> @Test public void more_testing() throws Exception {</div><div> System.out.println("more testing in the subclass");</div><div> }</div><div> @Test public void little_more_testing() throws Exception {</div>
<div> System.out.println("little more testing in the subclass");</div><div> }</div><div>}</div><div><br></div><div><br></div><div><br></div><div>******** stdout dell'esecuzione ******** </div><div>I'm another Super init</div>
<div>I'm a Super init</div><div>I'm another Sub init</div><div>I'm a Sub init</div><div>more testing in the subclass</div><div>I'm another Super init</div><div>I'm a Super init</div><div>I'm another Sub init</div>
<div>I'm a Sub init</div><div>little more testing in the subclass</div><div>I'm another Super init</div><div>I'm a Super init</div><div>I'm another Sub init</div><div>I'm a Sub init</div><div>Just a test in the superclass</div>
<div>I'm another Super init</div><div>I'm a Super init</div><div>I'm another Sub init</div><div>I'm a Sub init</div><div>Yet another test in the superclass</div><div> </div></div><div><br></div><div>Notare che:</div>
<div><ul><li>Non sei costretto ad avere una superclasse astratta, e' solo comune fare cosi' (non mi dilungo a spiegare perche', non sarebbe OT)</li><li>L'ordine di esecuzione dei @Before di una classe e' indeterminato, ma l'ordine tra classi e' determinato</li>
<li>Le teardown si comportano alla stessa maniera al contrario (cioe' prima le sottoclassi e poi le superclassi, l'annotazione per loro e' ovviamente @After)</li></ul><div><br></div></div><div>Ciao</div><div>Giuliano</div>
<div><br></div>-- <br>Piergiuliano Bossi<br>Blog: <a href="http://thinkingbox.wordpress.com/" target="_blank">http://thinkingbox.wordpress.com/</a><br>Twitter: <a href="http://twitter.com/thinkingbox" target="_blank">http://twitter.com/thinkingbox</a> (English)<br>
Twitter: <a href="http://twitter.com/scatolapensante" target="_blank">http://twitter.com/scatolapensante</a> (Italiano)<br><div>Google+: <a href="https://plus.google.com/u/0/108187981162465525118" target="_blank">https://plus.google.com/u/0/108187981162465525118</a></div>
</div></div>