D
D
Dmitry_Zhariy2011-12-30 22:22:50
Unit testing
Dmitry_Zhariy, 2011-12-30 22:22:50

Unit Tests and Asserts for Strings?

Gentlemen Programmers and Testers,
I have a very simple question, but very important for me:
Test:
If I enter the search query “Hello world” into Google,
then the title line of the search results should contain “Hello world”
How would you implement the line of the verification code (Assert ) for this test?
Answers are accepted in any programming language you know.
Thanks in advance and Happy New Year!
UPD.
Thanks for the replies, I would like to clarify the question: the actual page title bar should contain (contain) and not be equal to (equal) “Hello world”.
Those. the actual title line could be "Hello World - Google Search - Opera" and the test should pass with this line, but not with this one: "Hi Beer - Google Search - Opera".

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
ddenisyuk, 2011-12-30
@ddenisyuk

Assert.assertTrue(title.contains("Привет мир"));

I
int03e, 2011-12-30
@int03e

response.should have_selector("title:contains('All your base are belong to us')")

A
asm0dey, 2011-12-31
@asm0dey

assertTrue("Hello world",title.getText());

V
Vladimir Chernyshev, 2011-12-31
@VolCh

PHPUnit:

$this->assertSelectEqual("title", "Привет мир", 1, file_get_contents("google.ru?q=Привет мир"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question