Skip to content

3. Classes

Anindya Bandopadhyay edited this page Dec 23, 2018 · 8 revisions

There are several ways to use this framework based on the developer's requirement.

Case 1

If the majority of the classes need to be tested in this package then the developer should use below mention object creator.

AssertObjectCreator assertObject = new AssertObjectCreator();

OR

// AssertObjectCreator assertObject = new AssertObjectCreator(false);  Deprecated
AssertObjectCreator assertObject = new AssertObjectCreator();

In this scenario, all the class will be loaded for unit testing and if the developer wants to ignore any class from this package then it could be done using @IgnoreClass annotation at the class level.

Illustration

org.pojotester.testing.mypack.dto

                             |- Test01

                             |- Test02

                             |- Test03 <@IgnoreClass>

                             |- Test04

                             |- Test05

Test01, Test02, Test04 and Test05 classes will be loaded and Test03 will be ignored.


Case 2

If the selected class needed to be unit tested in a package then the developer should use below mention object creator.

// AssertObjectCreator assertObject = new AssertObjectCreator(true);  Deprecated
AssertObjectCreator assertObject = new AssertObjectCreator();
assertObject.doLoadClassesAskedFor();

In this scenario, only classes which are marked as @TestThisClass annotation at class level will be loaded for unit testing.

Illustration

org.pojotester.testing.mypack.dto

                             |- Test01 <@TestThisClass>

                             |- Test02

                             |- Test03 <@TestThisClass>

                             |- Test04

                             |- Test05

Test01 and Test03 classes will be loaded and Test02, Test04 & Test05 will be ignored.


If developer do not want to test toString , hashCode and equals overridden methods.

Case 3

If developer do not want to test overridden equals method.

assertObject.doNotTestEqualsMethod();

Case 4

If developer do not want to test overridden hashCode method.

assertObject.doNotTestHashCodeMethod();

Case 5

If developer do not want to test overridden toString method.

assertObject.doNotTestToStringMethod();

Case 6

If developer do not want to test any overridden methods of Object class. toString, hashCode and equals

assertObject.doNotTestObjectClassOverriddenMethods();

All Constructors testing

Case 7

If the developer want to test all the constructors of a class for unit testing.

assertObject.doTestAllConstructors();

NOTE:- Annotation, interface, enum and an abstract class will not be loaded.

Clone this wiki locally