Presentation is loading. Please wait.

Presentation is loading. Please wait.

Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.

Similar presentations


Presentation on theme: "Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel."— Presentation transcript:

1 Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel

2 2 Day 8 Unittest Basics

3  A Python language version of JUnit  Also referred to as PyUnit  Created in 1997 by Erich Gamma and Kent Beck ◦ Erich Gamma ◦ Erich Gamma - well known as one of the “Gang of Four” who gave us the now classic Design Patterns book. ◦ Kent Beck ◦ Kent Beck is equally well known for his groundbreaking work in the software discipline known as Extreme Programming  The underlying testing model (xUnit) is on its way to becoming the standard framework for any language. 3 xUnit frameworks are available for: ASP, C++, C#, Eiffel, Delphi, Perl, PHP, Python, REBOL, Smalltalk, and Visual Basic xUnit frameworks are available for: ASP, C++, C#, Eiffel, Delphi, Perl, PHP, Python, REBOL, Smalltalk, and Visual Basic

4  A semi-complete application.  Provides a reusable, common structure that can be shared between applications.  Developers incorporate the framework into their own application and extend it to meet their specific needs.  Differs from toolkits by providing a coherent structure, rather than a simple set of utility classes. 4

5 Examines the behavior of a distinct unit of work  A unit of work is a task that is not directly dependent on the completion of any other task.  In a Unit Testing framework: ◦ Each unit test must run independently of all other unit tests. ◦ Errors must be detected and reported test by test. ◦ It must be easy to define which unit tests will run. 5

6  test fixture ◦ preparation needed to perform one or more tests, ◦ any associate cleanup  test case ◦ smallest unit of testing. It checks for a specific response to a particular set of inputs ◦ unittest provides a base class, TestCase, which may be used to create new test cases  test suite ◦ collection of test cases, test suites, or both ◦ used to aggregate tests that should be executed together  test runner ◦ component which executes tests and reports the result. 6

7  A test case is created by sub-classing unittest.TestCase  Individual tests are defined with method names that start with the letters 'test'. 7  This naming convention informs the test runner about which methods represent tests. class AutoSuggest is a subclass of unittest.TestCase Name of a method which defines a testcase, starts with 'test'

8  The setUp() and tearDown() methods allow you to define instructions that will be executed before and after each test method. 8  Individual tests are defined with method names that start with the letters 'test'  Each test uses TestCase assert* methods to check for an expected result. o assertEqual() o assertTrue() o assertFalse() o etc. setUp() and tearDown() methods are for preperation and cleanup assert* methods are used to verify actual outcome against expected result

9 9 MethodChecks that assertEqual(a, b)a == b assertNotEqual(a, b)a != b assertTrue(x)bool(x) is True assertFalse(x)bool(x) is False assertIs(a, b)a is b assertIsNot(a, b)a is not b assertIsNone(x)x is None assertIsNotNone(x)x is not None assertIn(a, b)a in b assertNotIn(a, b)a not in b assertIsInstance(a, b)isinstance(a, b) assertNotIsInstance(a, b)not isinstance(a, b) assertRaises(assertRaises(exception)) MethodChecks that assertAlmostEqual(a, b)round(a-b, 7) == 0 assertNotAlmostEqual(a, b)round(a-b, 7) != 0 assertGreater(a, b)a > b assertGreaterEqual(a, b)a >= b assertLess(a, b)a < b assertLessEqual(a, b)a <= b assertRegexpMatches(s, r)r.search(s) assertNotRegexpMatches(s, r)not r.search(s) assertItemsEqual(a, b) sorted(a) == sorted(b) and works with unhashable objs assertDictContainsSubset(a, b) all the key/value pairs in a exist in b assertMultiLineEqual(a, b)strings assertSequenceEqual(a, b)sequences assertListEqual(a, b)lists assertTupleEqual(a, b)tuples assertSetEqual(a, b)sets or frozensets assertDictEqual(a, b)dicts

10  TestCase: class that extends the unittest.TestCase class. ◦ Contains one or more tests represented by testXXX methods. ◦ Used to group together tests that exercise common behaviors.  TestSuite - an aggregation of individual tests cases and test suites ◦ A convenient way to group together tests that are related. 10

11 1. Start by extending the test class from the standard unittest.TestSuite. 2. Instantiate a new TestSuite object() 3. Add test cases to the TestSuite object 11


Download ppt "Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel."

Similar presentations


Ads by Google