Use jmock in eclipse RCP Development

Source: Internet
Author: User

During unit testing, jmock can easily build a mock object, greatly improving the time for writing test cases. This article describes how to use jmock for unit testing in RCP development.

1. Import the jmock package


In eclipse RCP development, the dependencies between packages are implemented through osgi, so it is more complicated. It's like JUnit is made into a plug-in eclipse, so I also use the tried-and-tested "plug-in from existing jar archives ".

  1. Download all jar packages (http://www.jmock.org/download.html) from jmock's website ).
  2. Go to eclipse and choose new project> plug-in development> plug-in from existing jar archives. then select "add external... ", select all jar files, and click Next. Enter a project name or something like this (I usually do not select "unzip the jar archives into project", so there are too many files after unzip .) Then, "Finish" is generated for the new jmock plugin.

2. Use jmock to write the test




Now we can use the generated jmock plugin to write the test.

First, we will build a new plugin project, in which we will write all the test cases. I believe that all RCP students know this. (In some of my practices, this test project is best performed in fragment form, which not only effectively isolates the test code, but also facilitates the use of the tested code for the test code, ).

After the project is created, we first need to modify its manifest. MF file, add the relevant plugin. Mainly add two plugins, one is JUnit, and the other is the one we just generated, such:

The plugin named XX. testutil in the figure contains jmock. Please note that
, The plugin of junit4 must be placed at the end of the list, at least back than jmock. Otherwise, there will be errors during the running.

Now, please write a test to try it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.