1 / 11

CSE446 Software Quality Management

CSE446 Software Quality Management. Orhan Ba şar Evren. Spring 2014. Yazılım ve Uyguluma Geliştirme Yöneticisi. Today’s Overview. JUnit : Java Unit Test Unit Tests What is JUnit ? Test method example JUnit annotations Assert statements Test Suits Parameterized Test. Unit Tests.

tamber
Télécharger la présentation

CSE446 Software Quality Management

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSE446 Software Quality Management Orhan Başar Evren Spring 2014 Yazılım ve Uyguluma Geliştirme Yöneticisi

  2. Today’s Overview • JUnit: Java Unit Test • Unit Tests • What is JUnit ? • Test method example • JUnit annotations • Assert statements • Test Suits • Parameterized Test CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  3. Unit Tests • A unit test is a piece of code written by a developer that executes a specific functionality in the code to be tested. • Test critical and complex parts of your application. • Ignoretrivial code. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  4. JUnit : Unit Test Framework for Java • JUnit is a test framework which uses annotations to identify methods that specify a test. • Typically these test methods are contained in a class, which is only used for testing. It is called a Test Class. • Test methods should not depend on other tests. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  5. JUnit : Test method example @Test public void testMultiply() { //Calculator class to be tested Calculator c = new Calculator (); //Check if multiply(2,2) returns 4 assertEquals(“2 x 2 must be 4”, 4, c.multiply(2,2)); } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  6. JUnit :JUnit Annotations • @Test : identifies a method as a test method. • @Test(expected = Exception.class) • @Test(timeout = 100) • @Before : Identified method executed before each test. Used for preparation of test enviroment • @After: Identified method executed after each test. Used for cleanup • @BeforeClass: Identified method executed once before the test. CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  7. JUnit : Assert statements • fail(String) : Let the method fail • assertTrue(String message, boolean condition): Checks that the boolean condition is true • assertEquals(String message, Object expected, Object actual) : Tests that two values ar the same. • assertNotNull(String message, Object object) checks that object is not null CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  8. JUnit : Test Suits • Test classes can be combined into a test suite. Running a test suite will execute all test classes in that suite in the specified order. @RunWith(Suite.class) @SuiteClasses({ ATest.class, BTest.class }) publicclassAllTests { } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  9. JUnit : Parameterized Test @RunWith(Parameterized.class) publicclassMyTest { privateintnum; publicMyTest(intnum) { this.num= num; } @Parameters publicstatic Collection<Object[]> data() { Object[][] data = new Object[][] { { 1 }, { 5 }, { 121 } }; returnArrays.asList(data); } @Test publicvoidtestMultiply () { Calculator c = newCalculator(); assertEquals("Result", num * num, c.multiply(num, num)); } } CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  10. JUnit :NetBeans Support • Auto generate test classes CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

  11. JUnit :NetBeans Support CSE446 Software Quality Management Spring 2014 – Orhan Başar Evren - Netaş

More Related