Merge lp://qastaging/~elopio/selenium-simple-test/print_elements into lp://qastaging/selenium-simple-test

Proposed by Leo Arias
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 376
Merged at revision: 370
Proposed branch: lp://qastaging/~elopio/selenium-simple-test/print_elements
Merge into: lp://qastaging/selenium-simple-test
Prerequisite: lp://qastaging/~elopio/selenium-simple-test/fix1166408-assert_text_with_no_text
Diff against target: 361 lines (+121/-56)
5 files modified
src/sst/actions.py (+54/-41)
src/sst/selftests/assert_text.py (+2/-13)
src/sst/selftests/element_to_string.py (+19/-0)
src/sst/tests/test_actions.py (+44/-2)
src/testproject/templates/index.html (+2/-0)
To merge this branch: bzr merge lp://qastaging/~elopio/selenium-simple-test/print_elements
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Approve
Review via email: mp+157904@code.qastaging.launchpad.net

Commit message

Added _element_to_string to get a printable version of the element.

To post a comment you must log in.
373. By Leo Arias

Improved the test with id.

Revision history for this message
Vincent Ladeuil (vila) wrote :

I don't think this is a good use of mock. It at least triggers my main reluctance about using it: the tests using mock in this proposal are not doubled with tests using the real code.

Can you try rewriting those tests ?

review: Needs Information
374. By Leo Arias

Reverted testproj.db.

375. By Leo Arias

added acceptance tests for element_to_string.

376. By Leo Arias

Improved the readability of the element_to_string unit tests.

Revision history for this message
Leo Arias (elopio) wrote :
Download full text (11.9 KiB)

<elopio> vila: please take a look at http://bazaar.launchpad.net/~elopio/selenium-simple-test/print_elements/revision/375
<vila> elopio: hehe, even shorter ! So you don't need the mock ones anymore right ? <evil grin>
<elopio> vila: I disagree with you there :)
<vila> elopio: I'm all ears
<elopio> vila: this tests are nice to have, but they don't test a unit of code, they are retesting things that are already tested in selenium, they depend on firefox to run, they are slower, and the set up for the test is done on an external file (index.html), thus are not as readable as the other ones.
<vila> elopio: ha, then don't write them this way
<elopio> vila: now I'm all ears ;)
<elopio> vila: the way to solve all those problems is with a unit test and mock. I agree there are some code paths not tested on the original
<elopio> for example, _get_text
<vila> elopio: your implementation could be more testable but it would mean to not rely as much on actions.py then to be able to test it with a simple hmtl snippet
<vila> elopio: didn't you implemented some helpers to get there without involving firefox ?
<elopio> vila: no, firefox is always needed. I tried with htmlunit, but it sucks.
<elopio> we could do something with phantomjs.
<elopio> that would make it faster than firefox, but still slower than the mocked unit test.
<vila> the mocked one is faster because it does less, but you don't get a clear idea of what 'less' means by just reading the tests, you need to know the implementation to write them which is... bad
<elopio> vila: I wrote them before implementing them.
<vila> elopio: knowing how the implementation will work as opposed to knowing only the API
<vila> elopio: you test actions._element_to_string but mock element.get_attribute
<vila> elopio: how do you know they are related ?
<elopio> knowing what the function does, not how it is implemented.
<elopio> it is a really low level function, so it's implementation is straight-forward.
<elopio> but the implementation could change, what the tests describe is what it does. When there's no id attribute, then get the text.
<elopio> lets say we have a way to test an html snipped without a huge delay
<elopio> then
<elopio> element = mock.Mock()
<elopio> element.get_attribute.return_value = None
<elopio> element.text = 'Test text'
<elopio> would be the same as
<elopio> element = '<p>Test text</p>'
<elopio> the latter is shorter and clearer, I agree.
<vila> elopio: no, the later is shor.. see ?
<vila> elopio: moreover, even after reading the mock tests thrice, I still don't get what they do, if I really want to understand, I need to look at the implementation
<vila> elopio: and I still don't understand why there is a if in test_element_with_id.mock.get_attribute but a single call...
<elopio> vila: maybe I can make them clearer, for example making a function called get_element_without_id, and that creates and return the mock.
<vila> elopio: you'll end up duplicating the implementation which is even worse ;)
<elopio> no, let me try.
<elopio> vila: here: http://bazaar.launchpad.net/~elopio/selenium-simple-test/print_elements/revision/376#src/sst/tests/test_actions.py
<elopio> once we have a beautifulsoup sele...

Revision history for this message
Vincent Ladeuil (vila) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches