O'Reilly logo

TestNg Beginner's Guide by Varun Menon

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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();
        else
          return 0;
      }
    
    }

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required