Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Junit 4.0

3,424 views

Published on

Published in: Technology, Business
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m77EgH } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m77EgH } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Junit 4.0

  1. 1. Junit 4.0 Daniel Cukier – IME – USP [email_address] MAC5700
  2. 2. Conteúdo <ul><li>Sobre o JUnit </li></ul><ul><li>Migrando do Junit 3 para 4 </li></ul><ul><li>Novidades da nova versão </li></ul><ul><li>Testes de Tempo e performance </li></ul><ul><li>J2MEUnit </li></ul><ul><li>Outros arcabouços </li></ul>
  3. 3. Sobre o JUnit <ul><li>Arcabouço para testes de unidades – pequenos testes para as várias partes (módulos, métodos, classes, etc) de um sistema </li></ul><ul><li>Usado fortemente em XP, TDD e outros métodos ágeis </li></ul><ul><li>Código fonte livre </li></ul><ul><li>Testes de unidades mostram a presença de erros, não a auência deles </li></ul>
  4. 4. Velho JUnit import junit.framework.TestCase; public class NovelaTest extends TestCase { public void test NovelaExiste() { ArquivoDeNovelas novelas = new ArquivoDeNovelas(); assertEquals (&quot;Arquivo deve possuir Sassaricando&quot;, true, novelas .possuiNovela(&quot;Sassaricando&quot;)) } } métodos da classe TestCase reflexão
  5. 5. Velho JUnit import junit.framework.TestCase; public class NovelaTest extends TestCase { public void setUp () { novelas = new ArquivoDeNovelas(); } public void tearDown () { novelas = null; } }
  6. 6. Migrando para Junit 4.0 import junit.framework.JUnit4TestAdapter; import org.junit.Test; import static org.junit.Assert.assertEquals; public class NovelaNovoTest { @Test public void novelaJaTerminou() { ArquivoDeNovelas novelas = new ArquivoDeNovelas(); assertEquals(&quot;Arquivo deve possuir Sassaricando&quot;, true, novelas .possuiNovela(&quot;Sassaricando&quot;)); } public static junit.framework.Test suite(){ return new JUnit4TestAdapter(NovelaNovoTest.class); } } não é subclasse de TestCase – classe normal não começa com ‘test’
  7. 7. Migrando para Junit 4.0 import junit.framework.JUnit4TestAdapter; import org.junit.Test; import static org.junit.Assert.assertEquals; public class NovelaNovoTest { @Test public void novelaJaTerminou() { ArquivoDeNovelas novelas = new ArquivoDeNovelas(); assertEquals(&quot;Arquivo deve possuir Sassaricando&quot;, true, novelas .possuiNovela(&quot;Sassaricando&quot;)); } public static junit.framework.Test suite(){ return new JUnit4TestAdapter(NovelaNovoTest.class); } } Importa Test Annotation Todos os testes são anotado com @Test Importa método de classe Importa JUnit4TestAdapter Usado para rodar usando JUnit runner antigo
  8. 8. Executando os testes <ul><li>A maioria dos ambientes de desenvolvimento ainda não suportam Junit 4 </li></ul><ul><li>JUnit4Adapter permite rodar testes do JUnit 4 nesses ambientes, usando o método suite() </li></ul><ul><li>Rodar via linha de comando: </li></ul><ul><li>java org.junit.runner.JUnitCore LibraryTest </li></ul>
  9. 9. Antes e Depois de Cada Teste import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; public class NovelaNovoTest { private ArquivoDeNovelas novelas; @Before public void rodaAntesDeCadaTeste() { novelas = new ArquivoDeNovelas(); } @After public void rodaDepoisDeCadaTeste() { novelas = null; } @Test public void testNovelaExiste() { assertEquals(&quot;Arquivo deve possuir Sassaricando&quot;, true, novelas .possuiNovela(&quot;Sassaricando&quot;)); } }
  10. 10. Antes e Depois de Cada Teste <ul><li>É possível ter quantos métodos @Before e @After quiser </li></ul><ul><li>Métodos @Before e @After são herdados das superclasses. Métodos @Before das superclasses são executados antes dos métodos @Before da subclasse. Métodos @After das superclasses são executados depois. </li></ul><ul><li>Objetivo: agrupar código comum a vários testes </li></ul>
  11. 11. Antes e Depois da Classe de Testes <ul><li>Somente um método por classe </li></ul><ul><li>Bom para inicializações demoradas </li></ul>@BeforeClass public void rodaAntesDeTodosOsTestes() { novelas = new ArquivoDeNovelas(); novelas.carregaDadosDaRede(); } @AfterClass public void rodaDepoisDeTodosOsTestes() { novelas = null; } Processamento pesado!
  12. 12. Exceções Esperadas <ul><li>Se exceção não for gerada, teste falha </li></ul>@Test public void testDivisaoPorZero() { try { int n = 2 / 0; fail(&quot;Dividiu por zero!&quot;); } catch (ArithmeticException success) { assertNotNull(success.getMessage()); } } @Test(expected=ArithmeticException.class) public void testDivisaoPorZero () { int n = 2 / 0; } ANTES JUnit 4
  13. 13. Teste de tempo <ul><li>Teste falha se demorar mais do que timeout </li></ul><ul><li>Útil para testes de redes e conexões com bancos de dados </li></ul><ul><li>Detalhe: @After não é executado caso falhe! </li></ul>@Test( timeout=500 ) public void buscaTodasAsNovelas(){ novelas.buscaTodas(); }
  14. 14. Teste de Tempo <ul><li>Aplicações modernas existem tempo de resposta máximo. </li></ul><ul><li>O tempo de resposta pode mudar na medida em que o sistema evolui </li></ul><ul><li>Testes de tempo garantem que o tempo de resposta máximo seja satisfeito, mesmo que o sistema se torne mais complexo </li></ul><ul><li>O sistema cresce em funcionalidades sem perder performance! </li></ul>
  15. 15. Outras Funcionalidades <ul><li>@Ignore – Para desabilitar temporariamente um teste </li></ul><ul><li>assertEquals(Object[] expected, Object[] actual) – compara elemento a elemento </li></ul>
  16. 16. Resumo <ul><li>Precisa do JDK 5 para rodar </li></ul><ul><li>Classes de teste não são subclasses de TestCase </li></ul><ul><li>Métodos não começam com ‘test’ </li></ul><ul><li>Métodos de asserção de classe </li></ul><ul><li>@Test para anotar um teste </li></ul><ul><li>@Before e @After para rodar antes e depois de cada teste. </li></ul><ul><li>@Test recebe parâmetro de timeout </li></ul>
  17. 17. Resumo <ul><li>@Test recebe parâmentro de excessão esperada </li></ul><ul><li>JUnit4Adapter permite rodar JUnit 4 nos runners antigos. </li></ul><ul><li>Testes do JUnit antigo rodam normalmente no JUnit 4 </li></ul>
  18. 18. J2MEUnit <ul><li>J2ME não possui reflexão, muito menos anotações! </li></ul><ul><li>Recursos limitados </li></ul>public Test suite() { TestSuite suite = new TestSuite(&quot;testes paciente DAO&quot;); suite.addTest(new InfoPacienteDAOTest(&quot;Teste adiciona Paciente&quot;, new TestMethod() { public void run(TestCase tc) throws Exception { ((InfoPacienteDAOTest) tc).testAddInfoPaciente(); } })); } Adicionando métodos
  19. 19. J2MEUnit imports … public class BorboletaTestRunner extends TestRunner { public BorboletaTestRunner() { super(); } protected void startApp () { start(new String[] { InfoPacienteDAOTest.class.getName(), FormPacienteTest.class.getName(), ExportPacienteTest.class.getName(), ImportPacienteTest.class.getName() }); } } Array de strings com nome de classes de teste
  20. 20. Outros Arcabouços Unit <ul><li>SQLUnit – testes para Stored Procedures (http://sqlunit.sourceforge.net/) </li></ul><ul><li>JPDFUnit – testa documentos PDF gerados dinamicamente (http://jpdfunit.sourceforge.net/) </li></ul><ul><li>XMLUnit – teste para arquivos XML (http://xmlunit.sourceforge.net/) </li></ul><ul><li>Watij – teste de aplicações Web em java (http://watij.xwiki.com/xwiki/bin/view/Main/WebHome) </li></ul>
  21. 21. Referências <ul><li>http://www-128.ibm.com/developerworks/java/library/j-junit4.html </li></ul><ul><li>http://www.instrumentalservices.com/media/articles/java/junit4/JUnit4.pdf </li></ul><ul><li>http://junit.sourceforge.net/doc/cookbook/cookbook.htm </li></ul><ul><li>http://j2meunit.sourceforge.net/doc.html </li></ul><ul><li>http://www.junit.org/ </li></ul><ul><li>http://en.wikipedia.org/wiki/Unit_test </li></ul>

×