Book Image

Eclipse Plug-in Development Beginner's Guide - Second Edition

By : Alex Blewitt
Book Image

Eclipse Plug-in Development Beginner's Guide - Second Edition

By: Alex Blewitt

Overview of this book

Eclipse is used by everyone from indie devs to NASA engineers. Its popularity is underpinned by its impressive plug-in ecosystem, which allows it to be extended to meet the needs of whoever is using it. This book shows you how to take full advantage of the Eclipse IDE by building your own useful plug-ins from start to finish. Taking you through the complete process of plug-in development, from packaging to automated testing and deployment, this book is a direct route to quicker, cleaner Java development. It may be for beginners, but we're confident that you'll develop new skills quickly. Pretty soon you'll feel like an expert, in complete control of your IDE. Don't let Eclipse define you - extend it with the plug-ins you need today for smarter, happier, and more effective development.
Table of Contents (24 chapters)
Eclipse Plug-in Development Beginner's Guide Second Edition
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – writing a simple JUnit 4 test case


This part explains how to write and run a simple JUnit 4 test case in Eclipse.

  1. Create a new Java project called com.packtpub.e4.junit.example.

  2. Create a class called MathUtil in com.packtpub.e4.junit.example.

  3. Create a public static method called isOdd that takes an int and returns a boolean if it is an odd number (using value % 2 == 1).

  4. Create a new class called MathUtilTest in a package com.packtpub.e4.junit.example.

  5. Create a method called testOdd with an annotation @Test, which is the way JUnit 4 signifies that this method is a test case.

  6. Click on the quick-fix to Add JUnit 4 library to the build path, or edit the build path manually to point to Eclipse's plugins/org.junit_4.*.jar.

  7. Implement the testOdd method as follows:

    assertTrue(MathUtil.isOdd(3));
    assertFalse(MathUtil.isOdd(4));
  8. Add an import static of org.junit.Assert.* to fix the compiler errors.

  9. Right-click on the project and choose Run As | JUnit Test, and the JUnit test view should be...