Skip to content

1.4 Test Framework (Scala)

Nepomuk Seiler edited this page Feb 2, 2012 · 1 revision

[Work in Progress]

Goals

  • Simply testing your datamining processes
  • Provide sophisticated testing dsl

Introduction

Knowing uses ScalaTest to provide a readable and expressive test language. You can run normal JUnit tests with ScalaTest, which allows a smooth integration into all common IDEs. Currently the Knowing Test Framework only makes use of the common Matchers, which we will look into later in more detail.

To test actors the Knowing Test Framework relies on the Akka TestKit which itself uses ScalaTest.

Getting started

The plugin de.lmu.ifi.dbs.knowing.test provides the Akka TestKit jar and all classes needed to write tests for your DPUs.

The ScalaTest jars are OSGi ready since version 1.7.RC1 and can be grabbed here:

Import dependencies to your project and you are ready to kick off. A simple test could look like

//Note: KnowingTest will aggreagte all these: ShouldMatchers,EventMatchers,TestKit
class MyTest extends FunSuite with ShouldMatchers with EventMatchers with KnowingTest with TestKit

 /**
 * Imaginary test on http://www.hakank.org/weka/iris.arff
 */
 test("Check Results") {
  ...
  val results = .. //of type Results(Instances, Some("train"))
  
  results.instances should have size(10)

  //Check Result type (Results, QueryResults, QueriesResults)
  results should be (aResult)

  //Check relation name
  results should have (name("iris"))

  //Check for weka.core.Instance
  results should contain(List(5.1,3.5,1.4,0.2,"Iris-setosa")) at(0)

  //Check for attribute type NUMERIC. Three should be there
  results shoud have (attribute(weka.core.Attribute.NUMERIC, 3))
  
  //Check for class attribute
  results should have(classAttribute)

  //Check for attribute named "sepallength"
  results should have (attribute("sepallength")) withType (weka.core.Attribute.NUMERIC)

  //Check if the result instances aren't sorted by the attribute "sepallength"
  results should not be (sortedBy("sepallength"))

  
 }
}

EventMatchers

Custom Matcher

Be Matcher

HaveProperty Matcher

Ideas

Custom

  • contain(Instance) | contain(List[AnyRef])
  • contain(List[Instance]) | contain(List[List[AnyRef]])
  • containQuery(Instance) containQuery(List[AnyRef])
  • containQueryResults(List[Instances])

Be

  • aResult, aQueryResul, aQueriesResult
  • sortedBy(attr:String)
  • empty
  • smallerThan
  • greaterThan

Be on instances header types

Have

  • attribute(String | Attribute | type | + count)
  • port(String)
  • instance(List[Any])
  • classValues(List[String])
  • classAttribute
  • attributeWithPrefix/Suffix(String)
  • header(Instances) | header(ArrayList[Attribute]) | header(List[Attribute])
  • relationValue(Instances)
  • name(String)