When and what for do you use ui tests? Also how do you test multilingual project?

Better start with second question. Assuming there is project which is using more than 1 programming language. Like java + php for back end, java script + whatever for front end.

Is it possible to use same language for such project unit tests? I.e. is it possible to test php code with tests written on java. I almost certain that it is not possible, still hope for miracle =)

And other question is ui tests are long and hard (harder than unit/module) to maintain. Thus to avoid automation hell one should create unit/module test if possible. And question is is there a situation when you have to create ui test because can't create unit/module/integration/... test?

Posted Dec 7, 2015, 3:19 PM UTC

39
tonnynerd•

As far as I know, no, you can't create unit tests for PHP on Java. But, a lot of languages have jvm versions with some level of interoperability with Java, like Python (Jython) and Ruby (JRuby). Depending on what are the languages in your system, you might be able to share some code, but you're probably better of testing every part of the system in the language it is written.

As for ui tests, yes, they tend to be more brittle and hard to maintain, and you should prefer unit tests. But there are things you can use to minimize it, like the page object pattern, for instance. Having ui tests in lieu of unit, though, I'd say you should consider it carefully. It might seem tempting to add ui tests to get some sort of coverage for parts that are hard to refactor, but they are harder to maintain and will break more often, and won't provide as much information when they fail, so, again, consider it carefully.

1
pydry•

Not unit tests, but this is how you write integration tests.

I usually write integration tests using this: http://hitchtest.com/ (written in python)

It can run services in more than one language like java and PHP or anything else which you can run as a service under linux: https://hitchtest.readthedocs.org/en/latest/api/generic_service_api.html

1
4ingOP•

problem of such method is here:

def load_website(self):
    """Navigate to website in Firefox."""
    self.driver.get(self.services['Django'].url())

i mean as far as i understand it is +1 framework for webdriver

my "general" idea is: "i want to avoid automation hell → i want to create tests that involve browser only when it is the only way to test functionality."

I.e.

  • if there is java function that calculate something (distance) i would rather create unit test then open browser and look at page.
  • if there is a javascript function witch send some ajax request i would rather create a unit test then open a browser and wait for ajax response
  • Thus when to "open a browser"? Only to check html?
1
pydry•

i mean as far as i understand it is +1 framework for webdriver

Only partially. Selenium is just one plugin which you install if you happen to be integration testing websites. There are about 8 or 9 other plugins. There's a command line plugin and a postgres plugin too, for instance. Java + PHP plugins are coming soon too.

my "general" idea is: "i want to avoid automation hell

I'm not sure what you'd define as automation hell but I see it as:

1 Brittle tests - https://hitchtest.readthedocs.org/en/latest/glossary/brittle_tests.html

2 Unrealistic tests: https://hitchtest.readthedocs.org/en/latest/glossary/test_realism.html

3 Tests that are tightly coupled to your code

I don't tend to worry too much about slowness though. You can always parallelize and run tests randomly in order to get snappy feedback about test failures.

Thus when to "open a browser"? Only to check html?

I wrote this to answer that question : https://hitchtest.readthedocs.org/en/latest/faq/when_should_i_use_a_unit_test_and_when_should_i_use_an_integration_test.html

I generally involve the browser for almost everything when testing web apps. The only exception in your list would be the function to calculate distance which you could write use unit tests to test without losing realism.

An ajax call I'd always do in the context of the browser since that's the only way to test it realistically. Moreover I'd probably test it in multiple browsers.

2
4ingOP•

Hm... interesting. Thanks. Will look into it.

PS

I'm not sure what you'd define as automation hell but I see it as: ...

  • lack of "unified test runner" – some (one, simple) tool like jenkins, or anything else. Looks like hitchtest also have this feature. Main idea is to have tool that simplify test run as much as possible. To "even 5 year kid can start tests". Reason: both programmers and testers should use this tool. Problem: different people = different knowledge, different os, different... everything.
  • lack of "reporting tool". I mean yes, all test tools create reports. But. Usually it is just command line (text) reports → they are good when you have small number of tests, 1, 10, 100, may be 1000. More... well... text files are pain to process, gather statistics, modify.
  • ice-cream cone structure (anti-pattern) http://watirmelon.com/2012/01/31/introducing-the-software-testing-ice-cream-cone/
1
pydry•

I personally think that the testing pyramid / ice cream cone is a crock of shit. The idea is based upon the presumption that end to end tests are naturally brittle and non-deterministic:

http://martinfowler.com/bliki/TestPyramid.html

Engineer them right, though, and they're no longer brittle.

Most of the work I did behind the scenes in this framework centered around clamping down on sources of brittleness.

1