Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

jDefend: One Configuration File for All Your Test Scenarios  : Page 4

How would you like to have a test driver that you don't need to recompile every time input parameters change?


advertisement

Custom Arguments
Custom arguments are used to describe custom objects. Custom argument tags take place within the scope of </Argument>. The custom arguments can be nested to any number of levels. As an example, our StudentManager has a method add that takes a Student object, which is itself a custom object. So to describe the Student object, you will have to write the following XML format:


<Id>
	</IdArgument Name="someName" Type="type" Value="value"/>
</Id>

You should replace "Id" with the actual Id defined as part of the <Argument> tag attributes. Remember the <Argument> tag for the testAdd method:




<Argument Num="1" Type="example.Student" VALUE="CustomType"
Id="StudentX">

StudentX is the declared Id. So, your Custom Argument tag will look like this:


<StudentX> 
<StudentXArgument Name="name" Type="String" Value="Subbu" /> 
</StudentX> 

However, the Address object also has another custom object, Address, as an instance variable. Also, the method to be invoked to set this address object value does not follow the standard "set" convention. That is, you don't have a standard setAddress method; you have addressIs(Address a) instead. You can handle this situation using your XML tags.


<StudentXArgument Name="course" Type="Address" Value="CustomType"
Method="addressIs" Id="Course"> <Address> <AddressArgument Name="street" Type="String" Value="1 Adams Ave" /> <AddressArgument Name="city" Type="String" Value="Atlanta" /> </Address> </StudentXArgument>

For a detailed description of the custom argument attributes, see the Custom Argument Attribute Descriptions table.

Custom Argument Attribute Descriptions

Name Name of the instance variable.
The assumption is that the instance variable name in the Student class has a public set method. Using the reflection, the Address object will be created and the setName method will be called with the value Subbu.
Type Indicates the type of argument.
This attribute supports all simple data types. For complex data types, this would be a fully qualified class name such as java.util.Vector.
E.g., String, int, java.util.Vector, Student
Value Indicates the value to be passed.
E.g., DolphinNose, for the method testFindStudent.
If the Type is a user-defined type or complex data type, Value should be set to CustomType.
Method The name of the method that should be called to set the value.
By default, this would be "set" along with an instance variable name. However, if your custom object does not have a standard setter method, you can always use the Method attribute to specify the method that should be invoked.

So, you have a nested CustomType situation (Address object as an instance variable inside Student). Follow the convention you used for describing the Student object: set the Value to CustomType and define the Id as "Course." The difference here is the Method attribute. Since you do not have a standard setAddress method, you have to list the method name explicitly.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date