fairingrey / actix-realworld-example-app

[UNMAINTAINED] Implementation of the RealWorld backend API spec in Actix, Rust's powerful actor system and most fun web framework.
524 stars 71 forks source link

Write proper unit tests and integration tests #20

Open frgomes opened 4 years ago

frgomes commented 4 years ago

Related: #19

IMHO, one of the major deficiencies of actix-web documentation and codebase is that examples may not be self-contained, being clean enough and straighforward enough for newcomers into the library. By "self contained" I mean: "copy from the browser, paste into two files: Cargo.toml and main.rs ... fire cargo and it works."

Writing an end-to-end, real world application, containing reasonable unit tests and integration tests would potentially eradicate this deficiency.

Also, since Actix 2.0 now employs async/await, several examples from the documentation website are just outdated and so, if you are a newbie and copy/paste the example... it will take you a number of hours until you realise that you were simply misguided.

In my case in particular, I've struggled a lot to write a proof of concept which looks like code in production. Examples in the documentation are incomplete (they are just snippets of code), not exercising real world scenarios, which render them sometimes almost useless... apart from the syntax they introduce or some mechanics they illustrate.

I had difficulties finding an example which "just works", which does something so mundane: a simple client code (using actix-web client, not anything else!) which sends a post request containing some JSON and receives some other JSON as response. There's no such example containing unit tests and integration tests (which just work!) as far as I know and, in order to build one, I had to invest a lot of time and effort digging into the code base of a number of repositories.

Then, finally the coin dropped after a number of hours: it does not work because I'm using Actix 2.0 but trying documentation from the website which assumes Actix 1.0.

So, once again: Writing proper unit tests and integration tests in a context of a real world application is a must. Ideally, employing Actix 2.0 as #19 suggests.

frgomes commented 4 years ago

I've created a proof of concept which hopefully will have some common real world scenarios, including unit tests and integration tests. It is not intended to replace this repository, but eventually it can be used as a contribution to this repository in future.

https://github.com/frgomes/poc-rust-actix

shirshak55 commented 4 years ago

yep actix 2.0 has examples but not so much proper unit and e2e testing that really creates problem for many people. And yes they have not updated guides but i think API docs is good for now.