Better tests with fongo




Doug Roper

fongo


Fake Mongo.
In memory.
Crazy fast.
Awesome logging.

Fongo + Untestable -> Testable.
Fongo + Testable -> Better.

how do we unit test collections?



def afterAll() = clinicalDataCollection.collection.drop()
def beforeEach() = clinicalDataCollection.remove()
def testSavingMeasurements = { val measurements = ... clinicalDataCollection.saveMeasurements(measurements) val persisted = clinicalDataCollection.find(measurements.id) assert(persisted === measurements) }

test on jenkins

Install Mongo on Jenkins.

No isolation.

Workarounds:
  • src/it/test
  • one job per mongo

Demo





SurveyDefinitionCollectionTest

mocks are brittle

class PonyService(...) {  def bestPony(): Pony = ponyDAO.find(bestQuery).head}

@Test def testPonyService() {
  val mockPonyDAO = mock[PonyDAO]
  when(mockPonyDAO.find()).thenReturn(Seq(new Pony("Pinkie Pie")))

  val service = new PonyService(mockPonyDAO)

  val pony = service.bestPony()
  assert(pony.name === "Pinkie Pie")
}

Fake > Mock

Build failed


1. bad code





:)

2. bad test





:(

Better tests with fongo

By Doug Roper

Better tests with fongo

  • 1,792