#2140 Fantom testing API (fant)

zapletnev Sun 12 May 2013

I want to find fantom testing API (analog for fantom compiler compiler::Compiler API fantom class where I can specify pods namespace, input/output directory, etc). I can find only fanx.tools.Fant java class that contains all testing functionality. It means that only one way to get test results: run fant and parse output text that is not convenient. Is where any other ways?

SlimerDude Sun 12 May 2013

Looking at it, Fant.java doesn't do much other than parse the Pods for test classes and run the test methods.

You can do this quite easily yourself in Fantom - for example, here's my own version of Fant that I've just cooked up in 2 minutes:

static Void main(Str[] args) {
  podName := "afIoc"
  
  Method[] testMethods := Pod.find(podName).types
    .findAll { it.fits(Test#) }
    .map |type->Method[]| { 
      type.methods.findAll { it.name.startsWith("test")} 
    }.flatten
  
  noOfPasses := 0
  noOfFailures := 0
  testMethods.each { 
    testInst := it.parent.make
    try {
      it.parent.method("setup").callOn(testInst, [,])
      it.callOn(testInst, [,])
      noOfPasses++
    } catch (Err e) {
      noOfFailures++
    } finally {
      it.parent.method("teardown").callOn(testInst, [,])
    }
  }
  
  echo("Ran ${testMethods.size} tests")
  echo(" - ${noOfPasses} passed")
  echo(" - ${noOfFailures} failed")
}

Login or Signup to reply.