Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

php - 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 sounded 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...