More test coverage and (rspec, scalacheck, and hunit)

I added more test coverage to botlist; basically adding tests by language. I don't have much to add to this entry except to say, here are some examples on how I used these test frameworks in botlist. Links to the actual libraries are at the bottom of the post.

RSpec


http://openbotlist.googlecode.com/svn/trunk/openbotlist/tests/integration/ruby/rspec

# create mock tests

include_class 'org.spirit.bean.impl.BotListCoreUsers' unless defined? BotListCoreUsers
include_class 'org.spirit.util.BotListUniqueId' unless defined? BotListUniqueId
include_class 'org.acegisecurity.providers.encoding.Md5PasswordEncoder' unless defined? Md5PasswordEncoder
include_class 'org.spirit.bean.impl.BotListProfileSettings' unless defined? BotListProfileSettings
include_class 'org.spirit.contract.BotListContractManager' unless defined? BotListContractManager

include_class 'java.text.SimpleDateFormat' unless defined? SimpleDateFormat
include_class "java.util.Calendar" unless defined? Calendar

include_class "org.spirit.contract.BotListCoreUsersContract"
include_class "org.spirit.bean.impl.BotListEntityLinks"

describe "Creating simple mock objects=" do

before(:each) do
@ac = $context
@rad_controller = @ac.getBean("radController")
@cur_sess_id = rand(1000000)
end

it "Should create the entity links" do
dao = @rad_controller.entityLinksDao
mock_link = BotListEntityLinks.new
mock_link.mainUrl = "http://www.google1.com"
mock_link.fullName = "bot_tester"
mock_link.urlTitle = "The Google"
mock_link.keywords = "google cool man yea"
mock_link.urlDescription = "google is the best yea man"
mock_link.rating = 0
dao.createLink(mock_link)
end

end

ScalaCheck


http://openbotlist.googlecode.com/svn/trunk/openbotlist/tests/integration/scala/spirit/tests


package org.spirit.check.tests

import org.spirit.lift.agents.model._

import org.scalacheck._
import org.scalacheck.Test._
import org.scalacheck.Gen._
import org.scalacheck.Arbitrary._
import org.scalacheck.Prop._

object ExampleTests {
def runTests() = {
val prop_ConcatLists = property((l1: List[Int], l2: List[Int]) =>
l1.size + l2.size == (l1 ::: l2).size)

Test.check(prop_ConcatLists)
}
}

HUnit



--
-- Test Stop Words

module Tests.Unit.TestStopWords where

import Test.HUnit

import Data.SpiderNet.Bayes
import Data.List

stopWordsDb = "../../var/lib/spiderdb/lexicon/stopwords/stopwords.tdb"

foo :: Int -> (Int, Int)
foo x = (1, x)

runTestStopWords = do
stopwords <- readStopWords stopWordsDb
let datatest = [ "the", "school", "is", "over", "there", "canada", "chicken" ]
rmwords = datatest \\ stopwords
putStrLn $ show rmwords
putStrLn $ "Stop Word Density=" ++
show (stopWordDensity "the school is over there canada chicken dogs" stopwords)

test1 :: Test
test1 = TestCase (assertEqual "for (foo 3)," (1,2) (foo 3))

allTests :: Test
allTests = TestList [ TestLabel "stop words" test1 ]

Resources


http://rspec.info/
http://code.google.com/p/scalacheck/

----

Comments

Popular posts from this blog

Is Java the new COBOL? Yes. What does that mean, exactly? (Part 1)

On Unit Testing, Java TDD for developers to write

JVM Notebook: Basic Clojure, Java and JVM Language performance