Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[dsdp-tm-dev] RSE Unit Tests 101

Hi all,

as promised on the committer call, I have checked in a very
simple Unit test for IFileService:

org.eclipse.rse.tests / FileServiceTest

and it immediately brought a bug to light:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=168586

I thought I'd give you a quick how-to for writing your
own unit tests:

0.) Ensure that in Window > Preferences > Java > Code Style
    > Code Templates > Code > New Files you have the proper
    Copyright Header, since you'll be creating new files

1.) Get the org.eclipse.rse.tests{.framework} plugins from
    CVS into your workspaces. You can use the 
    rse-releng-committer.psf project set or directly grab
    it from the Repository.
    Decide in what package your test class should live.
    Create a new test package in the org.eclipse.rse.tests
    plugin if necessary.

2.) Create your test class: New > Class > (Yourname)
    Baseclass: RSEBaseConnectionTestCase

3.) Write setUp(), tearDown(), testXXX() methods as needed.
    setUp() is called before each testXXX in order to 
    initialize the test environment. It makes sense to
    use it (and some instance variables) to avoid having
    to type stuff over and over again.
    - You may need to add dependencies to the 
      org.eclipse.rse.test/META-INF/MANIFEST.MF

4.) Test your test: In the Launch Config Dialog (Run...),
    select the "Junit Plug-in Test / RSE Combined Test Suite"
    - This one is checked-in from Uwe
    - Right click > Duplicate, rename it (YOUR test)
    - Common Tab > Mark as Local
    - Test class > press "Search", enter YOUR test class

--> When run, the Launch will start up PDE and run your test.
You can also debug it. Results are shown in a "Junit" view.

5.) Hook up your test with the main test suite so it's
    added to the nightly builds:
    - If you created a new package, create a suite like
      RSEFileTestSuite (copy&paste) and hook that one
      up in RSECombinedTestSuite.suite()
    - Otherwise, hook your test into the suite() method
      of any existing TestSuite
    - If you want a Launch for the Suite, just use the
      Suite as the test class

--> That's it! Real simple, isn't it?

Here is a bit more generic advice for using Junit:
* Use instance variables for re-used settings
* Use helper methods for setting up things etc.
* Tests should be independent from each other
* Tests need to be named testAbcDefGhi -- use test
  method names that are clear with respect to what
  they test, it will be easier to identify failure.

You can start with really really simple things and 
make them more complex going along. With the FileServiceTest,
it currently works for the LocalFileService only, but
I'm planning to make it generic such that it can run
against any Ihost that provides any IFileServiceSubSystem.


Cheers,
--
Martin Oberhuber
Wind River Systems, Inc.
Target Management Project Lead, DSDP PMC Member
http://www.eclipse.org/dsdp/tm


Back to the top