问题
I've recently found Karate framework for testing Web Services. But there is also Spock framework providing similar (to my mind) functionality. What are the differences between the frameworks? I would like to suggest our testers to take a look at it.
回答1:
Developer of Karate here. I have only read about Spock but here's my PoV.
Karate is laser-focused on testing HTTP web-services, and therefore is designed to manipulate and perform assertions on JSON and XML. As a result - you do not need POJO-s any-more.
Whereas Spock is a general-purpose testing framework. It is based on Groovy, so it reduces the verbosity somewhat compared to if you just used Java, and it adds the BDD flavor that is of value in expressing test-cases. Just like Karate, it has a structure to test-cases, a life-cycle (before hooks, environment switching, etc.) data-driven test helpers, and integration with unit-test and reporting frameworks such as JUnit.
A key difference IMO is that while Spock and similar frameworks try to abstract away the verbosity of Java in favor of a cleaner more readable syntax - they succeed only to a certain extent. Karate almost bypasses Java completely (from a test writers PoV) which means that you are operating in the exact 'layer' that you want to - which is HTTP and JSON / XML.
I'd like to point you to this comparison between Karate and REST-assured - since some of the points would apply to Spock as well, and it would be a helpful reference for any team evaluating Karate.
来源:https://stackoverflow.com/questions/45352358/karate-vs-spock