Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a JUnit like test tool MyJUnit that extends class TestHarness. In TestHarness, there are two overloading methods boolean checkEqual(int actual, int expected) and boolean

Develop a JUnit like test tool MyJUnit that extends class TestHarness. In TestHarness, there are two overloading methods boolean checkEqual(int actual, int expected) and boolean checkEqual(double actual, double expected) for comparing primitive data type values.

The MyJUnit can accept multiple testlet class names, such as java MyJUnit RectangleTestlet BoxTestlet, to test testlet classes in order. Most importantly, the MyJUnit tool must be able to handle new testlet classes in the future without a need of code change. All the testlet classes implement an interface called TestletIF which defines a runTest method. Feel free to specify the argument for the method.

Please prepare two testlet classes to test the two classes Rectangle and Box, respectively. The Rectangle class has a method int getArea(int w, int h), while the Box class has a method double getVolume(double l, double w, double h). Assume all input variables should range between 1 and 10. Perform boundary value analysis for the two classes through the two testlets.

Hint for Part 2 Here shows a sample snippet for RectangleTestlet. The ??? is an object used to run checkEqual. This object should be passed in not created by using the keyword new, such as new TestHarness(). In other words, the TestHarness object should be the same one that creates the Testlets instead of being a new object.

package pkg;

public class RectangleTestlet implements Testlet {

Rectangle r = new Rectangle();

public void runTest() {

???.checkEqual(r.getArea(5,5), 25); // need object ??? to run checkEqual

}

}

To create an object of RectangleTestlet, you will need to take advantage of Reflection. Simple snippet code is shown below. This way of coding allows the tool to take in whatever Testlet classes that are developed in the future.

package pkg;

public class MyProg {

public static void main(String[] args){

Class c = Class.forName(args[0]); // The args[0] would be pkg.RectangleTestlet

Object o = c.newInstance();

// Now cast the object to a Testlet class.

// With the Testlet object, you can run its method.

}

}

The problem is how to access the TestHarness object from your Testlet object. A good solution is to pass the TestHarness object to the Testlet's method. In that case, you can utilize the TestHarness object to do all sorts of comparison that are available in the TestHarness object.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

d. What is the value of the sample correlation coefficient?

Answered: 1 week ago

Question

What is electric dipole explain with example

Answered: 1 week ago

Question

What is polarization? Describe it with examples.

Answered: 1 week ago