Why No One Uses Your Test Framework
slideshare.net
slideshare.net
Lots of people have written variations on assertions and mocks. But where's the full-stack test harness for a Rails app with heavy JS usage, that runs at a reasonable speed, gives us useful traces on the client and server, and doesn't break when I slightly rework my HTML?
Or, where's the tool for testing integration with REST services outside your control, that doesn't depend on the real service most of the time, but can be told to run against the real service as a sanity check when you want to? (Like Ruby's VCR, but better.)
Or, how about a test framework that accurately emulates mobile browsers and automatically?
I'm not getting on anyone's case for not having written this stuff. Because hey, I'm just as guilty of not solving these problems as is the rest of the community. But if you want to make a testing tool that people will absolutely love, solve some of these problems really elegantly. (I know, easier said than done. And yes, some tools have solved some of these problems to some extent. But I'd consider each of my examples to be an ongoing pain point for developers.)
If you're talking Python, Lettuce does this is Python, there also is Splinter. You can run selenium with a headless firefox quite easily with Xvfb.
If you're talking rails, Capybara has drivers for Webkit (QI), selenium and even PhantomJS. Their speed is variable, but it's not too bad.
On the "HTML changes break my tests," I'd argue that A) you should write your front end tests not tied to the HTML if at all possible. Refer to elements by semantic names, not XPath or CSS selectors. And be smart about your steps. Make your submit_form() method actually look for a submit button in more than one way. B) you shouldn't have more than a handful of full stack frond end tests. They're hard to write, slow, and don't give much help telling you WHAT went wrong. Most of the time the ROI is only there for verifying a few user paths, but not much more than that.
Also, I don't understand mocks in Python. Say I have a class Foo that has a method "bar" that I want to override. OK:
class FakeFoo(Foo):
def bar(self):
print "OH HAI"
Done. It's built in to the freakin' language :)If you honestly think that sub-classing is equivalent to mocking/stubbing, you don't understand the purpose of the activity.
my $bar = 0;
class FakeFoo {
sub bar { return $bar }
}
my $thing = ThingToTest->new( foo => FakeFoo->new );
$foo = 42;
is $thing->make_bar_two_bigger, 44;
$foo = -10;
is $thing->make_bar_two_bigger, -12;
Mock enthusiasts would write: my $fake_foo = Mock->new( Foo->class )->instance;
$fake_foo->return_sequence( bar => [42, -10] );
my $thing = ThingToTest->new( foo => $fake_foo );
is $fake_foo->make_bar_two_bigger, 44;
is $fake_foo->make_bar_two_bigger, -12;
ok $fake_foo->ensure_exhausted('bar');
Yes, it's less lines, but I think it's harder to read because the values are being set up long before they're used.See http://www.python.org/dev/peps/pep-0417/ and http://www.gossamer-threads.com/lists/python/dev/973274
More recently, a Google contribution to unittest.py added a huge number of self.assertThisThatOrTheOther() methods. The new methods were designed to have better diagnostic messages for test failures (i.e. diffs between expected and actual).
Much needed test discovery was added by Michael Foord.
Third-party testing modules like py.test and nose.py are popular substitutes for unittest.py. They use a light-weight syntax and are joy to use.
One question, is there a web testing framework for python that they do like/recommend?
Since he's being a dick about it, I very much understand your desire to pedantically point out his error of terminology. Unfortunately, "strong" typing is a very overloaded term, which has never had a widely agreed meaning amongst either academics or practitioners. There are generally two camps: "strong" === "static", and "strong" === "no dynamic coercions", and neither is technically incorrect.