PDA

View Full Version : AOP and Unit testing ?



vickyk
Sep 2nd, 2004, 07:18 AM
Hi All,
I have a idea evolving in my mind , it is using the AOP with the Unit Testing .It can be done with the JUnit , I am in a process of evaulation/analysing this idea and would be glad to hear opinion from the community.

Regards
Vicky

Rod Johnson
Sep 3rd, 2004, 03:07 AM
Vicky

I've successfully used AOP in unit tests by injecting certain checks into methods via AOP. (Invariant checks etc). Is this what you had in mind?

Rgds
Rod

vickyk
Sep 3rd, 2004, 04:03 AM
Vicky
I've successfully used AOP in unit tests by injecting certain checks into methods via AOP. (Invariant checks etc). Is this what you had in mind?

Rod ,
I am not able to understand your statement clearly , ok let me just put a raw design down .Considering a class A as


public class A {
public String opn(String s)
{
return s.toUpperCase();
}
}

The Test case class follows :


import junit.framework.*;
public class ATest extends TestCase{
// Define All the Objects to be Tested
private A a = new A();
// Populate all the Objects needed to be Tested
protected void setUp(){
// Populate the Objects need for Test.The Population can be done using the properties
// File
}
public void testOpn(){
//
String inputData = "Vicky"; // 1) Advisor(InputDataAdvisor) should prepare the InputData Object
String expectedValue = "VICKY"; // 2) Advisor(ExpectedResultAdvisor) will prepare the ExpectedValue Object
String executionValue = a.opn(inputData);
assertEquals(expectedValue, executionValue); // 3)Advisor will check the object Contents.Its Data
}
public static void main(String args[]) {
junit.textui.TestRunner.run(ATest.class);
}
}

Now I dont want to write the ATest , rathar than I will focus on the Interceptor which basically will try to
1) Prepare the I/p data.
2) Prepare the o/p Data
3) Verify the execution result
Here I will prepare the standard Advisors and can be reused across the projects , just need to maintain the xml files .
The concept seems to make the UnitTesting simple but needs a serious thought process .What do you think?

Regards
Vicky