Capuchin - Unit Test Framework
Monkey Forums/User Modules/Capuchin - Unit Test Framework| 
 | ||
| Hi everyone, I want to share with you this framework I've been working on for testing my code. Currently is very basic and handles only boolean and numeric values, but I plan on adding more stuff to it. I've already used it on my SAT module to test that it works correctly. You can check the repo here: https://github.com/ilovepixel/capuchin And here you can see a small example of it: running 
Import capuchin
Import mojo
Class NumberTest Extends Test Implements iSpec
	Method New()
		Super.New()
		It("0 Should be equal to value", Self)
		It("10 should be lower than value", Self)
		It("99 should be grater or equal to value", Self)
		It("25.6 should be lower or equal to to value", Self)
	End
	Method Execute:Void (testNum:Int, spec:Spec)
		Select (testNum)
			Case 0
				spec.Expect(0).ToEqual(0)
				'spec.Done()' <--- forcing a timeout
			Case 1
				spec.Expect(10).BeLowerThan(100)
				spec.Done()
			Case 2
				spec.Expect(99).BeGreaterOrEqualTo(99)
				spec.Done()
			Case 3
				spec.Expect(25.6).BeLowerOrEqualTo(25)
				spec.Done()
		End
	End
End
Class BoolTest Extends Test Implements iSpec
	Method New()
		Super.New()
		It("True should be equal to value", Self)
		It("False should be equal to value", Self)
		It("True should not be equal to value", Self)
		It("False should not be equal to value", Self)
	End
	Method Execute:Void (testNum:Int, spec:Spec)
		Select (testNum)
			Case 0
				spec.Expect(True).ToEqual(True)
				spec.Done()
			Case 1
				spec.Expect(False).ToEqual(True) '<-- Forcing a fail
				spec.Done()
			Case 2
				spec.Expect(True).NotEqual(False)
				spec.Done()
			Case 3
				spec.Expect(False).NotEqual(True)
				spec.Done()
		End
	End
End
Class GameTest Extends App
	Field testEnv:TestEnviroment
	Method OnCreate:Int ()
		testEnv = New TestEnviroment()
		testEnv.Describe("Checking numbers", New NumberTest())
		testEnv.Describe("Checking booleans", New BoolTest())
		testEnv.Start()
		SetUpdateRate(60)
		Return 0
	End
	Method OnUpdate:Int ()
		testEnv.Update()
		Return 0
	End
	Method OnRender:Int ()
		Cls()
		testEnv.Draw()
		Return 0
	End	
End
Function Main:Int ()
	New GameTest()
	Return 0
End
To check the framework being used on a real monkey module you can check here: http://dev.shin.cl/sat-monkey/tests/ Cheers, Felipe |