Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Unit Testing with Mock Objects (Week 6)

This article is posted by IBM and explains how the Mock Object can be used. In this article we will find some of the benefits of using Mock Objects for writing Unit tests for objects that act as mediators. Unit testing has become widely accepted for software development. When you write an object you must also provide an automated test class containing methods that put the object through its paces, calling its various public methods with various parameters and making sure that the values returned are appropriate.When we’re dealing with simple data or service objects, writing unit tests is straightforward. However, many objects rely on other objects or layers of infrastructure. When it comes to testing these objects, it is often expensive, impractical, or inefficient to instantiate these collaborators. For example, to unit test an object that uses a database, it may be burdensome to install, configure, and seed a local copy of the database, run your tests, then tear the local database down again.A mock object conforms to the interface of the real object, but has just enough code to fool the tested object and track its behavior. For example, a database connection for a particular unit test might record the query while always returning the same hardwired result. As long as the class being tested behaves as expected, it won’t notice the difference, and the unit test can check that the proper query was emitted.

Here are some of the common coding style for testing with mock objects:

  • Create instances of mock objects
  • Set state and expectations in the mock objects
  • Invoke domain code with mock objects as parameters
  • Verify consistency in the mock objects

Citation
https://www.ibm.com/developerworks/library/j-mocktest/


From the blog Table of Code by Andon S and used with permission of the author. All other rights reserved by the author.

Whether or not to use old test data

This week I read a great blog on starting from scratch or
using old test documentation. The writer formed the blog based on a question
asked by one of his fellow testers, “How can I find old test documentation for
a completed feature so I can re-use those test on a similar new feature?”.
My initial thought was that’s actually not a bad idea, but
the more I read the more I was swayed and started thinking about times when I
was either asked about a similar situation or posed the same question. Though I
wasn’t software testing at the time nor even in the industry this can be
applied to other scenarios as well.
While I do think that it is a good idea to track and refer
to past tests to see what has been done, I agree with the writer that “a
skilled tester can usually come up with better tests…today, from scratch.” He
makes many valid points and I will go over a couple that I thought to me stood
out, you can read the blog to get the rest if you’d like.
  • ·        
    A skilled tester knows more about testing today
    than they did last month.

         How true. The more you do something the
more you learn about it and the better you become at          it.
  • The product-under-test is different today than
    it was last month.  It might have new code, refactored code, more users,
    more data, a different reputation, a different platform, a different time of
    the year, etc.

          As the development process moves through
the different iterations, things change. Looking at             past tests may help, but
more probably than not it will probably slow you down. You have first           locate
the tests that were done and figure out what the tester was thinking if it wasn’t
you, and             then try and decide whether or not it even applies to the new code. By
the time you figure that             stuff out I would imagine you could have written
several test cases according to the latest                     iteration.

  • The test environment might be different.

          This is true as well, things seemingly change
frequently so you may have changed the                         environment and once again wasting time
seeing what you or someone else did.

The bottom line here is that while in some cases the old
data may help, but more than likely it will, in my opinion slow you down. One
more thing I think can happen is can stagnate your thought process as you are
looking at old ideas instead of coming up with new ideas.
http://www.testthisblog.com/2016/03/start-from-scratch-vs-old-test.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.testthisblog.com/2016/03/couple-automated-checks-with-product.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.testthisblog.com/2016/02/automated-checking-is-very-human.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.softwaretestingmagazine.com/knowledge/how-to-give-better-code-reviews/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SoftwareTestingMagazine+%28Software+Testing+Magazine%29
http://www.developsense.com/blog/2016/05/testers-dont-prevent-problems/

From the blog format c: /s by c-braley and used with permission of the author. All other rights reserved by the author.

Whether or not to use old test data

This week I read a great blog on starting from scratch or
using old test documentation. The writer formed the blog based on a question
asked by one of his fellow testers, “How can I find old test documentation for
a completed feature so I can re-use those test on a similar new feature?”.
My initial thought was that’s actually not a bad idea, but
the more I read the more I was swayed and started thinking about times when I
was either asked about a similar situation or posed the same question. Though I
wasn’t software testing at the time nor even in the industry this can be
applied to other scenarios as well.
While I do think that it is a good idea to track and refer
to past tests to see what has been done, I agree with the writer that “a
skilled tester can usually come up with better tests…today, from scratch.” He
makes many valid points and I will go over a couple that I thought to me stood
out, you can read the blog to get the rest if you’d like.
  • ·        
    A skilled tester knows more about testing today
    than they did last month.

         How true. The more you do something the
more you learn about it and the better you become at          it.
  • The product-under-test is different today than
    it was last month.  It might have new code, refactored code, more users,
    more data, a different reputation, a different platform, a different time of
    the year, etc.

          As the development process moves through
the different iterations, things change. Looking at             past tests may help, but
more probably than not it will probably slow you down. You have first           locate
the tests that were done and figure out what the tester was thinking if it wasn’t
you, and             then try and decide whether or not it even applies to the new code. By
the time you figure that             stuff out I would imagine you could have written
several test cases according to the latest                     iteration.

  • The test environment might be different.

          This is true as well, things seemingly change
frequently so you may have changed the                         environment and once again wasting time
seeing what you or someone else did.

The bottom line here is that while in some cases the old
data may help, but more than likely it will, in my opinion slow you down. One
more thing I think can happen is can stagnate your thought process as you are
looking at old ideas instead of coming up with new ideas.
http://www.testthisblog.com/2016/03/start-from-scratch-vs-old-test.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.testthisblog.com/2016/03/couple-automated-checks-with-product.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.testthisblog.com/2016/02/automated-checking-is-very-human.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.softwaretestingmagazine.com/knowledge/how-to-give-better-code-reviews/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SoftwareTestingMagazine+%28Software+Testing+Magazine%29
http://www.developsense.com/blog/2016/05/testers-dont-prevent-problems/

From the blog format c: /s by c-braley and used with permission of the author. All other rights reserved by the author.

Whether or not to use old test data

This week I read a great blog on starting from scratch or
using old test documentation. The writer formed the blog based on a question
asked by one of his fellow testers, “How can I find old test documentation for
a completed feature so I can re-use those test on a similar new feature?”.
My initial thought was that’s actually not a bad idea, but
the more I read the more I was swayed and started thinking about times when I
was either asked about a similar situation or posed the same question. Though I
wasn’t software testing at the time nor even in the industry this can be
applied to other scenarios as well.
While I do think that it is a good idea to track and refer
to past tests to see what has been done, I agree with the writer that “a
skilled tester can usually come up with better tests…today, from scratch.” He
makes many valid points and I will go over a couple that I thought to me stood
out, you can read the blog to get the rest if you’d like.
  • ·        
    A skilled tester knows more about testing today
    than they did last month.

         How true. The more you do something the
more you learn about it and the better you become at          it.
  • The product-under-test is different today than
    it was last month.  It might have new code, refactored code, more users,
    more data, a different reputation, a different platform, a different time of
    the year, etc.

          As the development process moves through
the different iterations, things change. Looking at             past tests may help, but
more probably than not it will probably slow you down. You have first           locate
the tests that were done and figure out what the tester was thinking if it wasn’t
you, and             then try and decide whether or not it even applies to the new code. By
the time you figure that             stuff out I would imagine you could have written
several test cases according to the latest                     iteration.

  • The test environment might be different.

          This is true as well, things seemingly change
frequently so you may have changed the                         environment and once again wasting time
seeing what you or someone else did.

The bottom line here is that while in some cases the old
data may help, but more than likely it will, in my opinion slow you down. One
more thing I think can happen is can stagnate your thought process as you are
looking at old ideas instead of coming up with new ideas.
http://www.testthisblog.com/2016/03/start-from-scratch-vs-old-test.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.testthisblog.com/2016/03/couple-automated-checks-with-product.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.testthisblog.com/2016/02/automated-checking-is-very-human.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+EricJacobsonSoftwareTestingBlog+%28Test+This+Blog+-+Eric+Jacobson%27s+Software+Testing+Blog%29
http://www.softwaretestingmagazine.com/knowledge/how-to-give-better-code-reviews/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+SoftwareTestingMagazine+%28Software+Testing+Magazine%29
http://www.developsense.com/blog/2016/05/testers-dont-prevent-problems/

From the blog format c: /s by c-braley and used with permission of the author. All other rights reserved by the author.