Содержание
- 2. Agenda What is Testing Testing Types Unit and Integration Testing JUnit Emma Coverage TestNG Parallel Tests
- 3. What is Testing Software testing is the process of program execution in order to find bugs.
- 4. Testing Types. Unit Testing Unit testing is a procedure used to validate that individual units of
- 5. Testing Types. Unit Testing Unit testing – the process of programming, allowing you to test the
- 6. Testing Types. Unit Testing Task: Implement functionality to calculate speed=distance/time where distance and time values will
- 7. Integration Testing Integration testing is the phase of software testing in which individual software modules are
- 8. Integration Testing Task: Database scripts, application main code and GUI components were developed by different programmers.
- 9. Unit / Integration Testing public class One { private String text; public One( ) { //
- 10. Unit / Integration Testing public class Two { private One one; public Two(One one) { this.one
- 11. Unit / Integration Testing public class Appl { public static void main(String[ ] args) { One
- 12. Unit / Integration Testing public class TwoTest { @Test public void TestResume( ) { One one
- 13. Unit / Integration Testing A method stub or simply stub in software development is a piece
- 14. Unit / Integration Testing public class One implements IOne { private String text; public One( )
- 15. Unit / Integration Testing public class Two { private IOne one; public Two(IOne one) { this.one
- 16. Unit / Integration Testing Stub – a piece of code used to stand in for some
- 17. Unit / Integration Testing public class TwoTest { @Test public void TestResume( ) { IOne one
- 18. Junit 3 import junit.framework.TestCase; рublic class AddJavaTest extends TestCase { protected void setUp( ) throws Exception
- 19. JUnit Assert class contains many different overloaded methods. http://www.junit.org/ https://github.com/kentbeck/junit/wiki assertEquals(long expected, long actual) Asserts that
- 20. JUnit assertSame(java.lang.Object expected, java.lang.Object actual) Asserts that two objects refer to the same object. assertNotSame(java.lang.Object unexpected,
- 21. Junit 4 import org.junit.Test; import org.junit.Assert; public class MathTest { @Test public void testEquals( ) {
- 22. JUnit To integrate tests, you can use a class TestSuite. public static void main(String[ ] args)
- 23. JUnit package com.softserve.edu; public class Rectangle implements IRectangle { private double height; private double width; public
- 24. JUnit public void setHeight(double height) { this.height = height; } public double getWidth( ) { return
- 25. JUnit package com.softserve.edu; public class Square { private IRectangle rectangle; public Square(double width) { rectangle =
- 26. JUnit public double Perimeter(int multiply) { double p = 1; for (int i = 0; i
- 27. JUnit
- 28. JUnit
- 29. JUnit
- 30. JUnit
- 31. JUnit package com.softserve.edu; import org.junit.Assert; import org.junit.Test; public class SquareTest { @Test public void testPerimeter( )
- 32. JUnit @Test public void testPerimeter2( ) { Square square = new Square(2); square.setSquare(new RectangleStub( )) double
- 33. JUnit Stub – a piece of code used to stand in for some other programming functionality.
- 34. Emma Coverage EclEmma – Java Code Coverage for Eclipse.
- 35. Emma Coverage
- 36. TestNG JUnit 4 and TestNG are both very popular unit test framework in Java. TestNG (Next
- 37. TestNG Setting up TestNG with Eclipse. Click Help –> Install New Software Type http://beust.com/eclipse in the
- 38. TestNG To create a new TestNG class, select the menu File/New/TestNG
- 39. TestNG The first page of the wizard will show you a list of all the public
- 40. TestNG The next page lets you specify where that file will be created
- 41. TestNG package com.softserve.edu; import org.testng.AssertJUnit; import org.testng.annotations.Test; public class RectangleTest { @Test public void Perimeter( )
- 42. TestNG Hierarchy of tests All tests belong to a sequence of tests (suite), include a number
- 43. TestNG Every available before and after configurators. Started it all in the order +- before suite/
- 44. TestNG You can create a TestNG Launch Configuration. Select the Run / Debug menu and create
- 45. TestNG You should change the name of this configuration. Then you choose to launch your TestNG
- 46. TestNG From a definition file You can select a suite definition from your project. It doesn't
- 47. TestNG You start tests in many different ways: from an XML file, from a method, a
- 48. TestNG The Summary tab gives you statistics on your test run, such as the timings, the
- 49. TestNG Basic usage import java.util.*; import org.testng.Assert; import org.testng.annotations.*; public class TestNGTest1 { private Collection collection;
- 50. TestNG @BeforeMethod public void setUp( ) { collection = new ArrayList( ); System.out.println("@BeforeMethod - setUp"); }
- 51. TestNG @Test public void testEmptyCollection( ) { Assert.assertEquals(collection.isEmpty( ),true); System.out.println("@Test - testEmptyCollection"); } @Test public void
- 52. TestNG Result @BeforeClass - oneTimeSetUp @BeforeMethod - setUp @Test - testEmptyCollection @AfterMethod - tearDown @BeforeMethod -
- 53. TestNG Expected Exception Test The divisionWithException() method will throw an ArithmeticException Exception, since this is an
- 54. TestNG Ignore Test TestNG will not test the divisionWithException() method import org.testng.annotations.*; public class TestNGTest3 {
- 55. TestNG Time Test The “Time Test” means if an unit test takes longer than the specified
- 56. TestNG Suite Test. The “Suite Test” means bundle a few unit test cases and run it
- 57. TestNG TestNG provides a “Grouping” feature to bundle few methods as a single unit for testing
- 58. TestNG @Test(groups="method1") public void testingMethod1_1( ) { System.out.println("Method - testingMethod1_1( )"); } @Test(groups="method4") public void testingMethod4(
- 59. TestNG You can execute the unit test with group “method1” only "http://beust.com/testng/testng-1.0.dtd" > Result Method -
- 60. TestNG Parameterized Test In TestNG, XML file or “@DataProvider” is used to provide vary parameter for
- 61. TestNG "http://beust.com/testng/testng-1.0.dtd" > Result: Parameterized Number is : 2
- 62. TestNG Test cases occasionally may require complex data types, which can’t be represented as a String
- 63. TestNG // This function will provide the parameter data @DataProvider(name = "Data-Provider-Function") public Object[ ][ ]
- 64. TestNG public class TestNGTest8 { private int number; private String msg; public void setNumber(int number){ this.number
- 65. TestNG import org.testng.annotations.*; public class TestNGTest9 { @Test(dataProvider = "Data-Provider-Function") public void parameterIntTest(TestNGTest8 clzz) { System.out.println("Number
- 66. TestNG Testing example. Converting the character to ASCII or vice verse. package com.softserve.edu; public class CharUtils
- 67. TestNG import org.testng.Assert; import org.testng.annotations.*; public class CharUtilsTest { @DataProvider public Object[ ][ ] ValidDataProvider( )
- 68. TestNG @Test(dataProvider = "ValidDataProvider") public void CharToASCIITest(final char character, final int ascii) { int result =
- 69. TestNG Dependency Test. TestNG uses “dependOnMethods“ to implement the dependency testing. If the dependent method fails,
- 70. TestNG. Parallel Tests Running Multithreading. Tests were performed simultaneously on multiple threads. public class ConcurrencyTest1 extends
- 71. TestNG. Parallel Tests Running @Test(threadPoolSize = 30, invocationCount = 100, invocationTimeOut = 10000) public void testMapOperations(
- 72. TestNG @Test(singleThreaded = true, // run in a single thread invocationCount = 100, invocationTimeOut = 10000)
- 73. TestNG public class ConcurrencyTest2 extends Assert { // some staff here @DataProvider(parallel = true) public Object[
- 74. TestNG Set parallel option at the date of the provider in true. Tests for each data
- 76. Скачать презентацию