mardi 5 juillet 2016

Keep data from one example to the next on spec2

I'm new to unit testing. I have a web application written in Lift and Scala. I have an data model that is effectively the main one. The standard testing framework for Lift is specs2.

This is what I want my first unit test to do:

  1. create an instance of that data model and fill it with sample data, then save it
  2. fetch that same data from the database, check that the data is correct
  3. delete the instance

First of all, is this the Right Thing to do?

But even if it is, this is my problem: the ID in the database is returned at the end of step 1. I need that ID in order to get the data in step 2.

The documentation for specs2 seems to say that what I need to do keep data from one step to the next (I think that what I call "step" it calls "Examples"), is to create Expectations. But I can't figure out how to use them that way based on the docs.

I could create a var that contains an Option[ObjectId] at class level that I'd set to Some[ObjectId] at step 1 and use at step 2. But that just feels very wrong.

Is there a clear best way to do this?

Aucun commentaire:

Enregistrer un commentaire