1 / 51

Test

Test. Advanced Programming in Java. Mehdi Einali. Agenda. Software Quality Psychology of test Software testing Unit Testing Test values Test Driven Development(TDD). A Cook. In surgery. A car maker. Quality Control. Quality should be tested

jaden
Télécharger la présentation

Test

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. Test AdvancedProgramming in Java MehdiEinali

  2. Agenda • Software Quality • Psychology of test • Software testing • Unit Testing • Test values • Test Driven Development(TDD)

  3. A Cook

  4. In surgery

  5. A car maker

  6. Quality Control • Quality should be tested • A product is not finalized, before the test • Different kinds of test, check different kinds of quality

  7. Software Quality • We are programmers • Programmers produce software • What are characteristics of a good software? • Many parameters. E.g. • Conformance to requirements • Performance • Time • Memory • Maintainability • Changeability • Different kinds of test, check different kinds of quality

  8. Quality and cost cost for correction

  9. Cost and quality • Poor quality system impose more cost burden • Large system suffer very much more from poor quality system

  10. Psychology of Test

  11. Some definitions • Testing is the process of demonstrating that errors are not present • The purpose of testing is to show that a program performs its intended functions correctly • Testing is the process of establishing confidence that a program does what it is supposed to do.

  12. Goal of test • Find errors or find out everything is ok? • Human activities is goal oriented • What does errors means? • Compile, Runtime, Logical Error • Logical is not ok function • What does ok means? • Based on software specification • Based on user interactions

  13. Why definition is important • Optimistic vs. Pessimistic • Divergent vs. Convergent Thinking • Success vs. Failure of Testing • Test Adequacy

  14. definition • Testing is the process of executing a program with the intent of finding errors. • Pessimistic • Somehow destructive • Should be by divergent thinking than convergent thinking • Success when is done • Formal • Precise • Comprehensive • Diligently • Adequacy • As much as needed???

  15. Software testing

  16. Test phases • Unit Testing • Integration Testing • System Testing • System Integration Testing • Acceptance Testing

  17. Test phases IntegratinTesing Unit Tesing System Tesing Unit User EnvironmentFunctionality RequirmentSpecification α β Software System System IntegrationTesing AccptanceTesting Deliver to Customer Integrated System

  18. Unit Integration Automatic System Manual System Integration When? By who/what Acceptance Performance Test What aspect? Security Interoperability Function On What? Whatkind of system Mobile Static Web App Dynamic

  19. What to do with Test Side Effects? • Testing a sample of the product • Simulation • Mathematical analysis • In software testing • Along with all of these techniques • And we can also test the software itself! • (Usually) no damage to the software

  20. Test Target • System Test • Test the system as a whole • For performance, correctness and conformance. • Unit Test • Test the units and modules • Test of a component • Test of a class • Test of a method

  21. How to Test Software • Manual Test • Try it! • Test Tools • Performance Test • Profiling • JProfiler, TPTP • Load Test • Jmeter • Test Code • Unit Tests • Test Teams

  22. profiling

  23. profiling • Form of dynamic program analysis that measures, for example, the space (memory) or time complexity of a program, the usage of particular instructions, or the frequency and duration of calls • Most commonly, profiling information serves to aid program optimization. • For java • Two build in tool(JConsole, VisualVM)

  24. jconsole • JConsole provides basic monitoring of the JVM run-time along with key resources such as CPU, memory and threads. • %JAVA_HOME%\bin\jconsole.exe

  25. visualvm • Same as jconsole • %JAVA_HOME%\bin\jvisualvm.exe • With different approach • More features • Garbage collector • Memory dump

  26. Unit testing

  27. Test Code • Business Code • The code, written for implementation of a requirement • Test Code • The code, written for test of an implementation

  28. Unit Testing • A process for the programmer • Not a test team procedure • For improving the code quality • Reduces bugs • Test of units of software • before the software is completed • Unit: method, class

  29. Classical Unit Testing • Writing main() method • Some printlns • Drawbacks?

  30. Drawbacks • Test code coupled with business code • In the same class • Written tests are discarded • One test at a time • The programmer executes the tests himself • Test execution is not automatic • The programmer should check the result of each test himself • The test is passed or failed? • The test result interpretation is not automatic

  31. A Good Unit Test Code • Repeatable • Automatic • Invocation • Acceptance (Pass/Failure) • JUnit helps you write such tests

  32. Xunit Never in the field of software development have so many owed so much to so few lines of code

  33. history • Kent Beck developed the first xUnit automated test tool for Smalltalk in mid-90’s • Beck and Gamma (of design patterns Gang of Four) developed JUnit on a flight from Zurich to Washington, D.C. • JUnithas become the standard tool for Test-Driven Development in Java (see Junit.org) • XUnittools have since been developed for many other languages (Cunit,PyUnit,CPPUnit,NUnit,PHPUnit,…)

  34. JUnit, First Example

  35. JUnit, The Green Bar

  36. publicclass Testing { @Test publicvoidtestNormal() { int[] array = {3,2,1,4}; int[] sorted = {1,2,3,4}; Business.sort(array); for (int i = 0; i < sorted.length; i++) { Assert.assertEquals(sorted[i], array[i]); } } @Test publicvoidtestEmptyArray() { int[] array = {}; try{ Business.sort(array); }catch(Exception e){ Assert.fail(); } Assert.assertNotNull(array); Assert.assertEquals(array.length, 0); } }

  37. Assertions • assertNull(x) • assertNotNull(x) • assertTrue(boolean x) • assertFalse(boolean x) • assertEquals(x, y) • Uses x.equals(y) • assertSame(x, y) • Uses x ==y • assertNotSame • fail()

  38. Annotations • @Test • @Before • @After • @BeforeClass • @AfterClass

  39. A Good Unit Test is • Automated • Through • Repeatable • Independence • Professional

  40. Test input values

  41. test input values?

  42. Test values • Infinite possible values • More than 60 unique group • Which ones should be chosen? • Input value partitioning • Boundary value analysis

  43. Test driven development

  44. Test Driven Development • Test First Development • Before writing a code, write the tests!

  45. TDD

  46. end

More Related