From: Jeff M. <cus...@us...> - 2002-09-02 10:24:40
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv1324/html Modified Files: faq.html Log Message: Added additions from ted and split into sections Index: faq.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/faq.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- faq.html 29 Aug 2002 12:57:50 -0000 1.1 +++ faq.html 2 Sep 2002 10:24:37 -0000 1.2 @@ -1,66 +1,128 @@ -<ul> - <li> +<h1>MockObject FAQ</h1> +<h2>General Questions About Mocks</h2> <h3>What's a mock object?</h3> - <p> - It's a thing! + + <p>A mock object is a "double agent" used to test the behavior +of other objects. First, a mock object acts as a faux implementation +of an interface or class that simulates the external behavior of a true implementation. +Second, a mock object observes how other objects interact with its +methods and compares actual behavior with preset expectations. When a discrepancy +occurs, a mock object can interrupt the test and report the anomaly. If the +discrepancy cannot be noted during the test, a verification method called +by the tester ensures that all expectations have been met or failures reported.<br> </p> - </li> - <li> + <h3>What's an expectation?</h3> - <p> - It's another thing! - </p> - </li> - <li> + + <p>When any component is used in a program, we anticipate a set of preconditions +and postconditions. For example, we might anticipate that a database connection +will be used once and then closed. We might also anticipate that a JDBC ResultSet +will be passed a certain set of parameters for use with a given SQL command. +A mock object can be told to expect conditions such as these, so that it +can report back when our expectations are not met. The MockObjects API has +refactored this mechanism into a framework of Expectation classes. </p> + <h3>Why should I bother?</h3> - <p> - </p> - </li> - <li> +<p>Today, most developers recognize the value of unit testing. But many developers +also find that creating and maintaining non-trivial unit tests becomes difficult +as products mature. Writing significant unit tests can tempt developers into +making objects "test-aware". This can complicate production code and begins +to defeat the purpose of unit testing. Mock objects simplify the creation +and maintenance of non-trivial unit tests by allowing us to test one object +at a time. Mock objects make it possible to test an object without its knowledge.</p> +<p> +Mock objects allow you to unit test your application independently of the +production infrastructure. Developers do not need access to a real database +to run the unit tests. The same is true of any external resource, including +hardware devices.</p> +<p> +Mock objects can also simulate states that may be difficult or time-consuming +to realize in a runtime environment. A mock object can throw any exception +or produce any error condition on demand. For example, using a real database, +to see how an object will react to an offline database you would have to +actually down the database. Using a mock JDBC connection, you can simulate +a dead database in one test and a live database in the next, all in a fraction +of a second.</p> + <p> +As products mature, and test suites grow larger, tracing the cause of a failed +test can become difficult. A mock implementation can test assertions each +time it interacts with production (or "domain") code. The test is then more +likely to fail at the right time and generate a useful message. </p> + <p> +We can also build base assertions about how domain objects are suppose to +work into our mock objects. These assertions can be applied automatically +whenever the mock object is used. This ensures that our base assertions remain +true as the application matures. </p> + <p> +We use mock objects because they allow us to quickly create inexpensive, +effective tests that are easy to maintain. </p> + + <h3>Do I have to change the way I write my programs?</h3> +<p>Usually not. In fact , mock objects should make it easier to test your programs +without making changes to your production objects. Generally, the better +designed your application, the easier it should be to test with mock objects. +If an application does not test well, there are usually ways to improve its +design and provide better testability. In practice, many developers +find that approaching new development with a test-first perspective helps +them write better programs more quickly. Writing tests for features helps +defines the objects we need to provide those features. Test-driven design +helps us discover the interfaces our objects actually need</p> + + <h3>What are some of the patterns used to create tests with mock objects?</h3> + <h3>Who discovered mock objects?</h3> + <h3>What is the difference between stub objects and mock objects?</h3> + + +<h2>About the Mock Object Implementation</h2> + + <h3>Why do I have to call setup???? to instead of set??? to add something to a map?</h3> <p> </p> - </li> - <li> + + <h3>Who do I contribute changes back to the mock objects project?</h3> <p> </p> - </li> - <li> + + <h3>What does it mean when I get a NotImplementedException?</h3> <p> </p> - </li> - <li> + + <h3>How do I write a mock?</h3> <p> </p> - </li> - <li> + + <h3>Why don't mocks verify their expectations?</h3> <p> </p> - </li> - <li> + + <h3>What are the alt.* packages for?</h3> <p> </p> - </li> - <li> + + <h3>What do I do if I can't find a mock for a class?</h3> <p> </p> - </li> - <li> + + <h3>Are there any tools to help create mocks?</h3> <p> </p> - </li> - <li> - <h3>Why are the internals of mock private when there just test classes?</h3> - <p> - </p> - </li> -</ul> + + + <h3>Why are the internals of mock private when there just test class?</h3> + <h3>What is the best practice for integrating mocks into a project?</h3> + +<h2>Other Questions</h2> + + <h3>What are the differences between the EasyMock and MockMaker approaches?</h3> + + |