Search code examples
scalalift

What is the best way to test a lift rest service?


I saw one can mock a HTTP request

What is the best practice?


Solution

  • That wiki article shows one way to unit tests Lift application, but it depends on specs1, you can still use part of it with specs2, but the nicer withSFor , etc calls don;t work.

    There is a version for specs2 here.

    And there is a version that will be part of Lift itself coming soon.

    From the gist I posted, see towards the end how there is an example of how to test a REST endpoint.

    [Update] And I tend to move my logic out of the REST object as much as possible, so I can write a lot of unit tests against simple objects, where I pass the info they expect.

    Things like validation go into those separate objects.

    And my favorite tools for testing are specs2 and scalacheck

    Hope that help.