HOW to use java.util.vector in test-data.xml file?

94 views
Skip to first unread message

WEIHNACH...@gmail.com

unread,
Mar 9, 2006, 5:08:40 AM3/9/06
to jtestcase
<param name="vector" type="java.util.Vector">1,2,3,4,5</param>

faustothegray

unread,
Mar 9, 2006, 7:06:10 AM3/9/06
to jtestcase
Hi WEIHNACHTSKONZERT :)

You have two options:
1) -- Use nested params:
<method name="testVector" test-case="simplehashmap">
<params>
<param name="vectorTest" type="java.util.Vector"
key-type="" value-type="java.lang.String">
<param name="">item1</param>
<param name="">item2</param>
<param name="">item3</param>
</param>
</params>
</method>

and the java test is :

public void testVector() throws Exception {

Vector testCases = null;
HashMap params = null;
_jtestcase = new JTestCase(dataFile);

testCases = _jtestcase.getTestCaseInstances("GetParamTest",
"testVector");

// for each test case
for (int i = 0; i < testCases.size(); i++) {
TestCaseInstance testCase = ((TestCaseInstance) testCases
.elementAt(i));
params = testCase.getTestCaseParams();

Vector vectorTest = (Vector) params.get("vectorTest");

assertTrue("vector has not the right size ", vectorTest.size() ==
3);

String item1 = (String) vectorTest.get(0);

assertTrue("vector first item is not equal to item1 ", item1
.equals("item1"));

String item2 = (String) vectorTest.get(1);

assertTrue("vector first item is not equal to item2 ", item2
.equals("item2"));

String item3 = (String) vectorTest.get(2);

assertTrue("vector first item is not equal to item3 ", item3
.equals("item3"));

}
}

---- 2) Use Jice for collections
http://jtestcase.sourceforge.net/jicecollections.html
(the example is really about hashmap but i'm sure it will be
easy to
figure out how to do for vector)

Let me know if this solves your problem

Fausto

zhu yanyan

unread,
Mar 9, 2006, 8:28:37 AM3/9/06
to jtes...@googlegroups.com
Hi, Fausto,
Thank you for your quick reply.
The problem is I am using Jtestcase version 2.2.0 now. And I've checked the forum on sf and yuqing Wang claimed handling complex data types could be done in version 2.0.0.
How shall I use the old version instead of using TestCaseInstance?
What I've done is
===========================================
1)     <method name="testLogin" test-case="loginTest">
            <params>
                <param name="numberOfIterations" type="java.lang.Integer">10</param>        
                <param name="userVector" type="java.util.Vector"
                key-type ="" value-type="java.util.String">
                <param name = "">user1</param>
                <param name = "">user2</param>
                </param>
          </params>
        </method>
2) in java
 public void testLogin() throws Exception {

String method = "testLogin";
            int countOfTestCases = _jtestcase.getCountOfTestCases(method);
            Vector testCaseNames = _jtestcase.getNameOfTestCases(method);

for (int i = 0; i < countOfTestCases; i++) {
             
                //get test case
                String testCase = (String) testCaseNames.get(i);
                int numberOfIterations = getTestCaseIntParameter(method, testCase,
                        "numberOfIterations", true);
              for (int k = 1; k <= numberOfIterations; k++) {
                                   Vector userVector = (Vector)getTestCaseVectorParameter(method, testCase, "userVector");
                                      System.out.println("If Vector is empty" + userVector.isEmpry());
                                      String userName = (String)userVector.get(1);
                                   login(userName);     }
}
And the output is the vector is empty.And the error message says "java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0"

What'sthe problem? Thank you for taking care!!!

==========================================================

faustothegray

unread,
Mar 9, 2006, 8:49:57 AM3/9/06
to jtestcase
Hi zhu,

Try to make sure that the method


Vector userVector =
(Vector)getTestCaseVectorParameter(method, testCase, "userVector");

you are passing the right values for "method" and "testCase" parameter.

I'm afraid I can't tell nothing more appropriate just from code
inspection.

My advice would be to upgrade to the last release, just because the use
API
tries to cope exactly with this type of problems.

If you still have your problem, then try to upload your testcase I'll
take a look
at it personally as soon as I can.

Fausto

Yuqing Wang

unread,
Mar 22, 2006, 10:08:52 AM3/22/06
to jtestcase
Hi, YuQing:

Thank you for your help, it works *_*

Kindly, regards
yanyan


On 3/9/06, Yuqing Wang <yuqing...@yahoo.com> wrote:
Hi YanYan,

I've been out of date from the latest veriosn of JTestCase for a while.
Luckily I still have the JTestCase 2.2.0 installed in my machine.
Here's the suggestion:

1) the data file is correct
2) try following code:

// get hashed params for this test case
Hashtable params = _jtestcase.getTestCaseParams("testLogin",
testCase);

try {
Vector userVector = (Vector)params.get("userVector");
...

Hope this helps.

Yuqing

Reply all
Reply to author
Forward
0 new messages