开发者

simple (non-unit) test framework, similar to .phpt, should evaluate output/headers/errors/results

I'm looking for a simpler test framework. I had a look at a few PHPUnit and SimpleTest scripts and I find the required syntactic sugar appalling. SnapTest soun开发者_如何学运维ded nice, but was as cumbersome. Apache More::Test was too procedural, even for my taste. And Symfony lime-test was ununique in that regard. BDD tools like http://everzet.com/Behat/#basics are very nice, but even two abstraction levels higher than desired.

Moreover I've been using throwaway test scripts till now. And I'm wondering if instead of throwing them away, there is a testing framework/tool which simplifies using them for automated tests. Specifically I'd like to use something that:

  • evaluates output (print/echo), or even return values/objects
  • serializes and saves it away as probe/comparison data
  • allows to classify that comparison output as passed test or failure
  • also collects headers, warning or error messages (which might also be expected output)
  • in addition to a few $test->assert() or test::fail() states

Basically I'm too lazy to do the test frameworks work, manually pre-define or boolean evaluate and classify the expected output. Also I don't find it entertaining to needlessly wrap test methods into classes, plain include scripts or functions should suffice. Furthermore it shouldn't be difficult to autorun through the test scripts with a pre-initialized base and test environment.

The old .phpt scripts with their --expect-- output come close, but still require too much manual setup. Also I'd prefer a web GUI to run the tests. Is there a modern rehersal of such test scripts? (plus some header/error/result evalation and eventually unit test::assert methods)


Edit, I'll have to give an example. This is your typical PHPUnit test:

 class Test_Something extends PHPUnit_Test_Case_Or_Whatever {
     function tearUp() {
         app::__construct(...);
     }
     function testMyFunctionForProperResults() {
         $this->assertFalse(my_func(false));
         $this->assertMatch(my_func("xyzABC"), "/Z.+c/");
         $this->assertTrue(my_func(123) == 321);
     }
 }

Instead I'd like to use plain PHP with less intermingled test API:

 function test_my_function_for_proper_results() {
     assert::false(my_func(false));
     print my_func("xyz_ABC");
     return my_func(123);
 }

Well, that's actually three tests wrapped in one. But just to highlight: the first version needs manual testing. What I want is sending/returning the test data to the test framework. It's the task of the framework to compare results, and not just spoon-feeded booleans. Or imagine I get a bloated array result or object chain, which I don't want to manually list in the test scripts.


For the record, I've now discovered Shinpuru.
http://arkanis.de/projects/shinpuru/
Which looks promising for real world test cases, and uses PHP5.3-style anonymous functions instead of introspection-class wrappers.


Have to say - it isn't obvious how your example of a simplified test case would be possible to implement. Unfortunately the convolutedness is - more or less - something that has to be lived with. That said, I've seen cases where PHPUnit is extended to simplify things, as well as adding web test runners, tests for headers, output etc (thinking SilverStripe here - they're doing a lot of what you want with PHPUnit). That might be your best bet. For example:

  • evaluates output (print/echo):
    • enable output buffering and assert against the buffer result
  • collect headers, warning or error messages
    • register your own handler that stores the error message
    • wget against urls and compare the result (headers and all)

Etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜