|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
strange behaviour with assertEqualshi!
i have a problem with assertEquals. i use it several times in my tests but at one point it starts behaving strange. what i do: //a string String expected2 = "\r" + "\t\t<table id=\"mainTable\" class=\"mainTable\" cellpadding=\"3\" cellspacing=\"0\">\r" + "\t\t\t<thead>\r" + "\t\t\t\t<tr> </tr>\r"+ "\t\t\t\t\t\t<tr class=\"tableColTitle\">\r"+ "\t\t\t<th style=\"width: 47px;\" "\t\t\t</thead>\r"+ "\t\t\t<tbody border=\"1\" class=\"tableContent\">\r"+ "\t\t\t<tr><td colspan=\"1\" style=\"border: 0.5px solid rgb( [..long string ..] "\t\t</table>\r" + "\t"; //testElement is a JSONObject String actual2 = testElement.getString("Abstract"); assertEquals("testText", testElement.get ("doMultiData")); assertEquals(expected2, actual2); System.out.println("after assert"); assertEquals("0", testElement.get ("textTemplate")); the problem: the 2. assertEquals call seems to have a problem. the String "after assert" is not printed and the remaining tests in this class are skipped, but the next test klass is still executed. it sounds confusing to me, so i have made a screenshot. i hope it makes things clearer. ("testAltPrepCompPlainText_tabelle" has this problem) The test is finished although some tests were not run and the symbol at the suite suggest its still running.... AND the test gets marked as passed but it should fail, because using assertTrue(expected2.equals(actual2)); fails. i first got this behaviour using junit4.5, so i updated to junit 4.7 but its still the same. i hope someone can help me. sjel -- Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 - sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser [Non-text portions of this message have been removed] |
|
|
Re: strange behaviour with assertEqualsSjel,
Your screenshot didn't come through. Are you sure the test is getting through to the second assertEquals call? David Saff On Wed, Aug 5, 2009 at 8:12 AM, Sjel Nim<sjel@...> wrote: > hi! > > i have a problem with assertEquals. > i use it several times in my tests but at one point it > starts behaving strange. > > what i do: > > //a string > String expected2 = "\r" + > "\t\t<table id=\"mainTable\" class=\"mainTable\" cellpadding=\"3\" cellspacing=\"0\">\r" + > "\t\t\t<thead>\r" + > "\t\t\t\t<tr> </tr>\r"+ > "\t\t\t\t\t\t<tr class=\"tableColTitle\">\r"+ > "\t\t\t<th style=\"width: 47px;\" > "\t\t\t</thead>\r"+ > "\t\t\t<tbody border=\"1\" class=\"tableContent\">\r"+ > "\t\t\t<tr><td colspan=\"1\" style=\"border: 0.5px solid rgb( [..long string ..] > "\t\t</table>\r" + > "\t"; > > //testElement is a JSONObject > String actual2 = testElement.getString("Abstract"); > > assertEquals("testText", testElement.get ("doMultiData")); > assertEquals(expected2, actual2); > System.out.println("after assert"); > assertEquals("0", testElement.get ("textTemplate")); > > > the problem: > > the 2. assertEquals call seems to have a problem. the String "after assert" is not printed and the remaining tests in this class are skipped, but the next test klass is still executed. > > it sounds confusing to me, so i have made a screenshot. i hope it makes things clearer. ("testAltPrepCompPlainText_tabelle" has this problem) > The test is finished although some tests were not run and the symbol at the suite suggest its still running.... > > AND the test gets marked as passed but it should fail, because using > assertTrue(expected2.equals(actual2)); fails. > > i first got this behaviour using junit4.5, so i updated to junit 4.7 but its still the same. > > i hope someone can help me. > > sjel > -- > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 - > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > > > [Non-text portions of this message have been removed] > > > > ------------------------------------ > > Yahoo! Groups Links > > > > |
|
|
Re: strange behaviour with assertEqualsHi!
Thanks for your answer! I uploaded the picture here: http://s3.directupload.net/images/090910/u5fr8z34.png "testAltPrepCompPlainText_tabelle" is the one with the "assertEquals(expected2, actual2);" that doesn't work. As you can see, the three following Tests are not executed. Also next to the red bar is mentioned that there are 2 errors, but there is only one test marked with the error-icon. Yes, I am sure it is the second assertEquals call. I noticed this is not a one time thing, i got the same behaviour in several places wehn i use assertEquals(string, string). So it doesn't seem to be the html-code in my string that causes this. for instance: 'assertEquals ("5", testClass.testObject.feedbackText);' doesn't work, but 'assertTrue (testClass.testObject.feedbackText.equals ("5"));' does. I hope this information helps to make my problem more observable, Sjel --- In junit@..., David Saff <david@...> wrote: > > Sjel, > > Your screenshot didn't come through. Are you sure the test is getting > through to the second assertEquals call? > > David Saff > > On Wed, Aug 5, 2009 at 8:12 AM, Sjel Nim<sjel@...> wrote: > > hi! > > > > i have a problem with assertEquals. > > i use it several times in my tests but at one point it > > starts behaving strange. > > > > what i do: > > > > //a string > > String expected2 = "\r" + > > "\t\t<table id=\"mainTable\" class=\"mainTable\" cellpadding=\"3\" cellspacing=\"0\">\r" + > > "\t\t\t<thead>\r" + > > "\t\t\t\t<tr> </tr>\r"+ > > "\t\t\t\t\t\t<tr class=\"tableColTitle\">\r"+ > > "\t\t\t<th style=\"width: 47px;\" > > "\t\t\t</thead>\r"+ > > "\t\t\t<tbody border=\"1\" class=\"tableContent\">\r"+ > > "\t\t\t<tr><td colspan=\"1\" style=\"border: 0.5px solid rgb( [..long string ..] > > "\t\t</table>\r" + > > "\t"; > > > > //testElement is a JSONObject > > String actual2 = testElement.getString("Abstract"); > > > > assertEquals("testText", testElement.get ("doMultiData")); > > assertEquals(expected2, actual2); > > System.out.println("after assert"); > > assertEquals("0", testElement.get ("textTemplate")); > > > > > > the problem: > > > > the 2. assertEquals call seems to have a problem. the String "after assert" is not printed and the remaining tests in this class are skipped, but the next test klass is still executed. > > > > it sounds confusing to me, so i have made a screenshot. i hope it makes things clearer. ("testAltPrepCompPlainText_tabelle" has this problem) > > The test is finished although some tests were not run and the symbol at the suite suggest its still running.... > > > > AND the test gets marked as passed but it should fail, because using > > assertTrue(expected2.equals(actual2)); fails. > > > > i first got this behaviour using junit4.5, so i updated to junit 4.7 but its still the same. > > > > i hope someone can help me. > > > > sjel > > -- > > Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 - > > sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser > > > > > > [Non-text portions of this message have been removed] > > > > > > > > ------------------------------------ > > > > Yahoo! Groups Links > > > > > > > > > |
|
|
Re: Re: strange behaviour with assertEqualsOn Thursday 10 September 2009 16:49:23 tris_0011 wrote:
> for instance: 'assertEquals ("5", testClass.testObject.feedbackText);' > doesn't work, but 'assertTrue (testClass.testObject.feedbackText.equals ("5"));' does. I don't know if it's related, but if `assertEquals(A, B)` does an `A.equals(B)`, your assertTrue is doing a B.equals(A), and if B isn't a String and has its own .equals, it's possible that it's miswritten to be more relaxed about equality. -- "There are not enough adjectives in the English Faye, language to describe how wrong you are." /Questionable Content/ Hewlett-Packard Limited Cain Road, Bracknell, registered no: registered office: Berks RG12 1HN 690597 England |
|
|
Re: strange behaviour with assertEqualsHi!
Yes, i think that's the answer. 'assertEquals ("5", testObject.feedbackText);' doesn't work, but 'assertEquals ("5", testObject.feedbackText.toString());' does the job. My problem is that testObject.feedbackText should be a String and not a Object, so i don't understand why should i use toString() on a String? Maybe it would help inexperienced users like myself to give an Error-Message instead of this behaviour? Thanks for your help! sjel --- In junit@..., Chris Dollin <chris.dollin@...> wrote: > > On Thursday 10 September 2009 16:49:23 tris_0011 wrote: > > > for instance: 'assertEquals ("5", testClass.testObject.feedbackText);' > > doesn't work, but 'assertTrue (testClass.testObject.feedbackText.equals ("5"));' does. > > I don't know if it's related, but if `assertEquals(A, B)` does > an `A.equals(B)`, your assertTrue is doing a B.equals(A), and if > B isn't a String and has its own .equals, it's possible that it's > miswritten to be more relaxed about equality. > > -- > "There are not enough adjectives in the English Faye, > language to describe how wrong you are." /Questionable Content/ > > Hewlett-Packard Limited Cain Road, Bracknell, registered no: > registered office: Berks RG12 1HN 690597 England > |
|
|
Re: Re: strange behaviour with assertEqualsOn Tuesday 15 September 2009 17:22:46 tris_0011 wrote:
> Hi! > > Yes, i think that's the answer. > 'assertEquals ("5", testObject.feedbackText);' doesn't work, but > 'assertEquals ("5", testObject.feedbackText.toString());' does the job. I would deduce that `testObject.feedbackText` is not a String. > My problem is that testObject.feedbackText should be a String and > not a Object, so i don't understand why should i use toString() on a String? If `testObject.feedbackText` "should be" a String, then either it has type String (in which case my deduction is broken), or it doesn't, in which case I'd add an assertion like assertTrue( "feedback text must be a String", testObject.feedbackText instanceof String ); [in my local code, I have an assert method `assertInstanceOf(Class, value)`, which checks that `value` has type `Class` or subclass thereof and provides a decent error message if it isn't.] > Maybe it would help inexperienced users like myself to give an Error-Message > instead of this behaviour? I don't think it's feasible for the machine to detect and usefully report this error. > > Thanks for your help! > sjel > > > --- In junit@..., Chris Dollin <chris.dollin@...> wrote: > > > > On Thursday 10 September 2009 16:49:23 tris_0011 wrote: > > > > > for instance: 'assertEquals ("5", testClass.testObject.feedbackText);' > > > doesn't work, but 'assertTrue (testClass.testObject.feedbackText.equals ("5"));' does. > > > > I don't know if it's related, but if `assertEquals(A, B)` does > > an `A.equals(B)`, your assertTrue is doing a B.equals(A), and if > > B isn't a String and has its own .equals, it's possible that it's > > miswritten to be more relaxed about equality. -- "If time remained, the reasons would have rhymed." - IQ, /Frequency/ Hewlett-Packard Limited registered office: Cain Road, Bracknell, registered no: 690597 England Berks RG12 1HN |
| Free embeddable forum powered by Nabble | Forum Help |