510 likes | 830 Views
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
E N D
Test AdvancedProgramming in Java MehdiEinali
Agenda • Software Quality • Psychology of test • Software testing • Unit Testing • Test values • Test Driven Development(TDD)
Quality Control • Quality should be tested • A product is not finalized, before the test • Different kinds of test, check different kinds of quality
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
Quality and cost cost for correction
Cost and quality • Poor quality system impose more cost burden • Large system suffer very much more from poor quality system
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.
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
Why definition is important • Optimistic vs. Pessimistic • Divergent vs. Convergent Thinking • Success vs. Failure of Testing • Test Adequacy
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???
Test phases • Unit Testing • Integration Testing • System Testing • System Integration Testing • Acceptance Testing
Test phases IntegratinTesing Unit Tesing System Tesing Unit User EnvironmentFunctionality RequirmentSpecification α β Software System System IntegrationTesing AccptanceTesting Deliver to Customer Integrated System
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
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
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
How to Test Software • Manual Test • Try it! • Test Tools • Performance Test • Profiling • JProfiler, TPTP • Load Test • Jmeter • Test Code • Unit Tests • Test Teams
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)
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
visualvm • Same as jconsole • %JAVA_HOME%\bin\jvisualvm.exe • With different approach • More features • Garbage collector • Memory dump
Test Code • Business Code • The code, written for implementation of a requirement • Test Code • The code, written for test of an implementation
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
Classical Unit Testing • Writing main() method • Some printlns • Drawbacks?
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
A Good Unit Test Code • Repeatable • Automatic • Invocation • Acceptance (Pass/Failure) • JUnit helps you write such tests
Xunit Never in the field of software development have so many owed so much to so few lines of code
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,…)
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); } }
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()
Annotations • @Test • @Before • @After • @BeforeClass • @AfterClass
A Good Unit Test is • Automated • Through • Repeatable • Independence • Professional
Test values • Infinite possible values • More than 60 unique group • Which ones should be chosen? • Input value partitioning • Boundary value analysis
Test Driven Development • Test First Development • Before writing a code, write the tests!