Problem with assertEqualsNoOrder and String arrays

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem with assertEqualsNoOrder and String arrays

Tobias Vejda

Hi All,

I am using TestNG version 5.5.0.1 with Eclipse 3.2 and am experiencing
problems with assertEqualsNoOrder and String arrays.

The following code fragment (using bogus data) fails although the
contents of the two arrays ist the same...

<code>
String[] array1 = new String[6];
String[] array2 = new String[6];

array1[0] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
aaaa";
array1[1] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
aaab";
array1[2] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
bfffd";
array1[3] = "/LongStringTest/SecondLevelTest/Test/aaaaaaacd";
array1[4] = "/LongStringTest/SecondLevelTest/Test1/bfffdd";
array1[5] = "/LongStringTest/SecondLevelTest/LongStringTest/Test3/
bfffdd";

array2[0] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
aaab";
array2[1] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
bfffd";
array2[2] = "/LongStringTest/SecondLevelTest/LongStringTest/Test3/
bfffdd";
array2[3] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
aaaa";
array2[4] = "/LongStringTest/SecondLevelTest/Test/aaaaaaacd";
array2[5] = "/LongStringTest/SecondLevelTest/Test1/bfffdd";

assertEqualsNoOrder(array1, array2);
</code>

I played around with the implementation and it seems that
assertEqualsNoOrder uses a HashSet to enforce "sorting" of the
elements of the arrays which, if my observation is correct, may be the
cause of this problem (as it does not guarantee a specific order of
its elements).

Are there any known issues with this function? Did I use it
incorrectly or miss something else?

Thanks,
Tobias


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem with assertEqualsNoOrder and String arrays

Alexandru Popescu ☀

Can you show us the failure?

./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator


On 2/22/07, Tobias Vejda <[hidden email]> wrote:

>
> Hi All,
>
> I am using TestNG version 5.5.0.1 with Eclipse 3.2 and am experiencing
> problems with assertEqualsNoOrder and String arrays.
>
> The following code fragment (using bogus data) fails although the
> contents of the two arrays ist the same...
>
> <code>
> String[] array1 = new String[6];
> String[] array2 = new String[6];
>
> array1[0] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
> aaaa";
> array1[1] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
> aaab";
> array1[2] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
> bfffd";
> array1[3] = "/LongStringTest/SecondLevelTest/Test/aaaaaaacd";
> array1[4] = "/LongStringTest/SecondLevelTest/Test1/bfffdd";
> array1[5] = "/LongStringTest/SecondLevelTest/LongStringTest/Test3/
> bfffdd";
>
> array2[0] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
> aaab";
> array2[1] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
> bfffd";
> array2[2] = "/LongStringTest/SecondLevelTest/LongStringTest/Test3/
> bfffdd";
> array2[3] = "/LongStringTest/SecondLevelTest/LongStringTest/Test/
> aaaa";
> array2[4] = "/LongStringTest/SecondLevelTest/Test/aaaaaaacd";
> array2[5] = "/LongStringTest/SecondLevelTest/Test1/bfffdd";
>
> assertEqualsNoOrder(array1, array2);
> </code>
>
> I played around with the implementation and it seems that
> assertEqualsNoOrder uses a HashSet to enforce "sorting" of the
> elements of the arrays which, if my observation is correct, may be the
> cause of this problem (as it does not guarantee a specific order of
> its elements).
>
> Are there any known issues with this function? Did I use it
> incorrectly or miss something else?
>
> Thanks,
> Tobias
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem with assertEqualsNoOrder and String arrays

Tobias Vejda

On 22 Feb., 17:32, "Alexandru Popescu"
<[hidden email]> wrote:
> Can you show us the failure?

The failure output is as follows...

Exception in thread "main" java.lang.AssertionError: : Lists differ at
element [3]: /LongStringTest/SecondLevelTest/LongStringTest/Test3/
bfffdd != /LongStringTest/SecondLevelTest/LongStringTest/Test/aaaa
expected:</LongStringTest/SecondLevelTest/LongStringTest/Test3/bfffdd>
but was:</LongStringTest/SecondLevelTest/LongStringTest/Test/aaaa>
        at org.testng.Assert.fail(Assert.java:84)
        at org.testng.Assert.failNotEquals(Assert.java:438)
        at org.testng.Assert.assertEquals(Assert.java:108)
        at org.testng.Assert.assertEquals(Assert.java:483)
        at org.testng.Assert.assertEqualsNoOrder(Assert.java:525)
        at org.testng.Assert.assertEqualsNoOrder(Assert.java:546)
        at
TestNGAssertEqualsNoErrorTest.main(TestNGAssertEqualsNoErrorTest.java:
47)

Tobias


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem with assertEqualsNoOrder and String arrays

Alexandru Popescu ☀

I am a bit puzzled. I just tried it out without any problems. Do you
think you can add some more details so that we can figure it out?

./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator


On 2/23/07, Tobias Vejda <[hidden email]> wrote:

>
> On 22 Feb., 17:32, "Alexandru Popescu"
> <[hidden email]> wrote:
> > Can you show us the failure?
>
> The failure output is as follows...
>
> Exception in thread "main" java.lang.AssertionError: : Lists differ at
> element [3]: /LongStringTest/SecondLevelTest/LongStringTest/Test3/
> bfffdd != /LongStringTest/SecondLevelTest/LongStringTest/Test/aaaa
> expected:</LongStringTest/SecondLevelTest/LongStringTest/Test3/bfffdd>
> but was:</LongStringTest/SecondLevelTest/LongStringTest/Test/aaaa>
>         at org.testng.Assert.fail(Assert.java:84)
>         at org.testng.Assert.failNotEquals(Assert.java:438)
>         at org.testng.Assert.assertEquals(Assert.java:108)
>         at org.testng.Assert.assertEquals(Assert.java:483)
>         at org.testng.Assert.assertEqualsNoOrder(Assert.java:525)
>         at org.testng.Assert.assertEqualsNoOrder(Assert.java:546)
>         at
> TestNGAssertEqualsNoErrorTest.main(TestNGAssertEqualsNoErrorTest.java:
> 47)
>
> Tobias
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem with assertEqualsNoOrder and String arrays

Tobias Vejda

On 23 Feb., 20:04, "Alexandru Popescu"
<[hidden email]> wrote:
> I am a bit puzzled. I just tried it out without any problems. Do you
> think you can add some more details so that we can figure it out?

That's a bit puzzling, I agree. Well, what type of information would
you need?

I am using Windows XP Prof, Java 1.5.0-10 and Eclipse 3.2.1 with
TestNG 5.5.0.1. My test only consists of the code I have posted before
put into a single @Test method. I am starting it from Eclipse as a
TestNG test which leads to the failure. (Actually I have also tried
running it as a plain Java class using your Assert class which lead to
the error output I have posted before. However, the failure remains
the same in either way.)

Tobias


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem with assertEqualsNoOrder and String arrays

Tobias Vejda
In reply to this post by Alexandru Popescu ☀

On Feb 23, 8:04 pm, "Alexandru Popescu"
<[hidden email]> wrote:
> I am a bit puzzled. I just tried it out without any problems. Do you
> think you can add some more details so that we can figure it out?

That is puzzling, I agree. Well, which type of information would you
need?

I am using Windows XP Prof, Java 1.5.0-10, Eclipse 3.2.1 and TestNG
5.5.0.1. The test case only consists of a single @Test annotated
method with the code posted before. It was started from Eclipse using
a TestNG configuration with default settings and gives the failure.
(Actually I have tried it as a plain Java class using the methods from
Assert and the result is the same.)

Tobias


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: Problem with assertEqualsNoOrder and String arrays

Alexandru Popescu ☀
In reply to this post by Tobias Vejda

I will copy the exact data you are using and try it again. This is
starting to look like a Heisenbug :-).

I'll keep you posted.

./alex
--
.w( the_mindstorm )p.
  TestNG co-founder
EclipseTestNG Creator


On 2/26/07, Tobias Vejda <[hidden email]> wrote:

>
> On 23 Feb., 20:04, "Alexandru Popescu"
> <[hidden email]> wrote:
> > I am a bit puzzled. I just tried it out without any problems. Do you
> > think you can add some more details so that we can figure it out?
>
> That's a bit puzzling, I agree. Well, what type of information would
> you need?
>
> I am using Windows XP Prof, Java 1.5.0-10 and Eclipse 3.2.1 with
> TestNG 5.5.0.1. My test only consists of the code I have posted before
> put into a single @Test method. I am starting it from Eclipse as a
> TestNG test which leads to the failure. (Actually I have also tried
> running it as a plain Java class using your Assert class which lead to
> the error output I have posted before. However, the failure remains
> the same in either way.)
>
> Tobias
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en
-~----------~----~----~----~------~----~------~--~---