Uploaded image for project: 'ZTL'
  1. ZTL
  2. ZTL-10

verifyEquals("1", null) won't fail a test case

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Normal Normal
    • None
    • 2.0.0
    • Core
    • None

      We expect that the following method calling should make a test case failed, but it doesn't.

      verifyEquals("1", null)
      
      Root Cause:

      The verifyEquals() finally will call assertEquals(). In assertEquals, it doesn't consider the above case. (s1 is String, s2 is null), hence it won't fail a test case.

      public class ZKSeleneseTestBase{
      
      	    /** Like JUnit's Assert.assertEquals, but knows how to compare string arrays */
      	    public static void assertEquals(String message, Object s1, Object s2) {
      	        if (s1 instanceof String && s2 instanceof String) {
      	            assertEquals((String)s1, (String)s2);
      	        } else if (s1 instanceof String && s2 instanceof String[]) {
      	            assertEquals((String)s1, (String[])s2);
      	        } else if (s1 instanceof String && s2 instanceof Number) {
      	            assertEquals((String)s1, ((Number)s2).toString());
      	        }
      	        else {
      	            if (s1 instanceof String[] && s2 instanceof String[]) {
      	                
      	                String[] sa1 = (String[]) s1;
      	                String[] sa2 = (String[]) s2;
      	                if (sa1.length!=sa2.length) {
      	                	if (message != null)
      	                		throw new Error(message + "\nExpected " + sa1 + " but saw " + sa2);
      	                	else
      	                		throw new Error("Expected " + sa1 + " but saw " + sa2);
      	                }
      	                for (int j = 0; j < sa1.length; j++) {
      	                    assertEquals(sa1[j], sa2[j]);
      	                }
      	            }
      	        }
      	    }
      }
      

            hawk hawk
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: