matryer / silk

Markdown based document-driven RESTful API testing.
http://silktest.org/
GNU General Public License v2.0
942 stars 67 forks source link

better body assertions: Specify kind of assertion to make #25

Closed matryer closed 8 years ago

matryer commented 8 years ago

Proposal: better bodies in Silk

Bodies in Silk could make use of the 'formatting' tag thing where not only the data type is specified, but also the kind of assertions that could take place:

``json(mode=exact)
{
  "name": "Silk",
  "released": 2016
}
``

The types of bodies could be:

The syntax highlight language specified could also drive which ParseBody function is called.

Cons

Other options to consider:

dahernan commented 8 years ago

Instead of rely in the user, what I think it makes for sense is rely on sensible defaults. The idea is if the content type is JSON just relay on the JSON non strict equal to assert the response (non strict is not taking into account order on the elements, with the exception of arrays), that should be ok for most of the users.

For advance users, in case of JSON maybe a JSON Schema helps (I don't know the best way to relate a response to a schema)

If the content type is not JSON, the exact match is the most sensible default, with the possibility of implementing more assertions for other content types for example XML

narqo commented 8 years ago

The idea itself looks reasonable, but I think json label should work as json(mode=same) by default. I think that simplicity of the silk's way of written test is one of it's strengths, so one should try to save it.

matryer commented 8 years ago

Agreed... I'm all for simplicity and will always listen to something that strips functionality out, rather than adds it.

Question is, which is the sensible default:

narqo commented 8 years ago

JSON isn't biased about the order of fields. I don't remember any use cases where strict matching could make big difference.

The order of fields could change through the time, e.g when API producer switch to another JSON marshaller (nodejs 0.10 and 4 might stringify JSON with different field order). But at the same time, no API consumer would be harmed by this change, as JSON is a scheme-less data structure.

felixLam commented 8 years ago

:+1: +1

Right now this keeps me from fully utilizing this beautiful tool, as I would like to minifiy the JSON on the server, but have it prettified in the docs. In addition there is no real reason to be overly strict about the order in the docs as @narqo mentioned (IMHO). I would also opt to have the docs specify the required fields in the JSON and have lenient tests in case extra fields are included. This would allow us to keep minimal tests and avoid updating the docs with unneeded information if we later add features elsewhere.

felixLam commented 8 years ago

I also agree that flagging json responses with three backticks and json should be enough to enable the "lenient" mode.

felixLam commented 8 years ago

I have implemented json and json(mode=subset) in #36

matryer commented 8 years ago

I wonder if we can use subset by default, and have strict or exact as the option?

felixLam commented 8 years ago

exact is currently missing, but should be easy to add. As for the default, I leave the decision up to you. subset seems to be the more developer friendly default IMHO.

matryer commented 8 years ago

I think we can get rid of subset and just have it as the default. So exact is the only option?

felixLam commented 8 years ago

@matryer so subset is default, same and exact as options?

felixLam commented 8 years ago

@matryer done. subset is now the default with same and exact as options.