|
From: T.J.Hunt <t.j...@op...> - 2010-12-22 14:38:58
|
The right way to do extensions like this is to create a new Expectation class. For example like https://github.com/moodle/moodle/blob/master/lib/simpletestlib.php#L105. You can then use that as $this->assert(new MyExpectation($parameters), $value); That is the best way for tests you will want to reuse a lot. In other situations, a simple helper method is fine, but as you say, the default display is unhelpful. You can improve the display with a custom reporter. For example: https://github.com/moodle/moodle/blob/master/admin/report/unittest/ex_reporter.php#L160. That does a good job of showing just the interesting bits of the stack-trace, but not all the layers of the simpletest library. All that code is GPL, so you can copy it if you are working to a suitable open source license. Tim. ________________________________________ From: Christoph Berendes [ber...@ne...] Sent: 22 December 2010 14:05 To: Help, advice, bugs and workarounds Subject: [Simpletest-support] customized assert methods? Hi - I've been using Simpletest successfully and happily for a few years -- thanks -- and now want to wade in a little deeper. In particular, I'd like to write some customized assertions, for instance function assertLoginSuccessful($userName, $passWord) { $this->setField('username',$userName); $this->setField('password',$passWord); $this->click('Login'); return $this->assertText('Login successful!'); } This works fine, but I'd like one more thing - if the assertText fails, I'd like to see the line where assertLoginSuccessful was called. It looks like I could hack this together myself by calling the assert method directly, but then it seems I have to recreate assertText. What's the right way to create new assert methods that behave like the built-in ones, and also build on the built-in ones? Thanks. Chris Berendes ------------------------------------------------------------------------------ Forrester recently released a report on the Return on Investment (ROI) of Google Apps. They found a 300% ROI, 38%-56% cost savings, and break-even within 7 months. Over 3 million businesses have gone Google with Google Apps: an online email calendar, and document program that's accessible from your browser. Read the Forrester report: http://p.sf.net/sfu/googleapps-sfnew _______________________________________________ Simpletest-support mailing list Sim...@li... https://lists.sourceforge.net/lists/listinfo/simpletest-support -- The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). |