Time for action – using JMock with TestNG

  1. Create a new Java Project named JmockTesProject in eclipse with the folder and file structure shown in the following screenshot:
    Time for action – using JMock with TestNG
  2. Open the file AreaFinder.java and add the following code to it:
    package main.java.org.test.mocking;
    public class AreaFinder {
      private final Calculator calculator;
      public AreaFinder(Calculator calculator) {
      this.calculator = calculator;
      public double getAreaOfCircle(double radius) {
        if(radius > 0)
          return calculator.multiply(Math.PI, calculator.square(radius));
        else if(radius <0)
          throw new IllegalArgumentException();
          return 0;

    The preceding class file is a sample file which ...

Get TestNg Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.