[rc] understanding verifyTrue, verifyFalse, assertTrue and assertFalse.

1,000 views
Skip to first unread message

jerald

unread,
Nov 25, 2010, 9:06:37 AM11/25/10
to Selenium Users
Hi,

I know that verify commands will add the errors and continue running
the program and will throw the errors when the test exits. But the
assert commands will throw errors when it assertion fails. This will
lead to stop the current execution of the test method.

I have two test methods in my test class extending
"SeleneseTestCase" . In this testA have verify commands and testB has
assert commands. When i run the test class, testA always passes the
test. Any one say why the testA is not failing.

package com.test;

import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.SeleneseTestCase;
import junit.framework.Test;
import junit.framework.TestSuite;

public class MyTest3 extends SeleneseTestCase
{

public void setUp() throws Exception
{
selenium = new DefaultSelenium("localhost",
Integer.parseInt("4444"), "*chrome", "http://localhost:8080/");
selenium.start();
}

public void testA() throws Exception
{
verifyTrue(false);
verifyTrue(true);
verifyFalse(false);
verifyFalse(true);
}
public void testB() throws Exception
{
assertTrue(false);
assertTrue(true);
assertFalse(false);
assertFalse(true);
}

public void tearDown() throws Exception
{
selenium.stop();
}

public static void main(String[] args)
{
junit.textui.TestRunner.run(suite());
}

public static Test suite()
{
return new TestSuite(MyTest3.class);
}
}

Brian Kitchener

unread,
Nov 29, 2010, 11:13:24 AM11/29/10
to Selenium Users
verify suppresses the exceptions that get thrown, so your test will
pass (because all errors got caught). What my tests do is when a
verify statement fails it adds the error message to a string. Then in
the teardown function, you assert that the string is empty. If its
not empty, it means a verify failed, so the assert fails, and the test
fails, and it will print out the string containing all verification
errors.

zago

unread,
Dec 15, 2010, 8:26:31 AM12/15/10
to Selenium Users
Hi Brian,

It was helpful!
But.. Can you tell me how you do this?
"What my tests do is when a verify statement fails it adds the error
message to a string."

Thanks

c.p.chrisK

unread,
Jan 6, 2011, 2:04:33 PM1/6/11
to Selenium Users
Add checkForVerificationErrors() at the end of the test method.
This will fail the testcase but will proceed through the test steps.
It will then dump the assertion errors at the end of the test.
Reply all
Reply to author
Forward
0 new messages