Unity Getting Started Guide
UnityGettingStartedGuide
UnityGettingStartedGuide
UnityGettingStartedGuide
UnityGettingStartedGuide
UnityGettingStartedGuide
User Manual: Pdf
Open the PDF directly: View PDF
.
Page Count: 4

Unity — Getting Started
Welcome
Congratulations.You’renowtheproudownerofyourveryownpileofbits!Whatareyougoing
todowithalltheseonesandzeros?Thisdocumentshouldbeabletohelpyoudecidejustthat.
Unityisaunittestframework.Thegoalhasbeentokeepitsmallandfunctional.The
coreUnitytestframeworkisthreefiles:asingleCfileandacoupleheaderfiles.These
teamuptoprovidefunctionsandmacrostomaketestingeasier.
Unitywasdesignedtobecrossplatform.ItworkshardtostickwithCstandardswhile
stillprovidingsupportforthemanyembeddedCcompilersthatbendtherules.Unity
hasbeenusedwithmanycompilers,includingGCC,IAR,Clang,GreenHills,Microchip,
andMSVisualStudio.It’snotmuchworktogetittoworkwithanewtarget.
Overview of the Documents
Unity Assertions Reference
ThisdocumentwillguideyouthroughalltheassertionoptionsprovidedbyUnity.Thisisgoing
tobeyourunittestingbreadandbutter.You’llspendmoretimewithassertionsthananyother
partofUnity.
Unity Assertions Cheat Sheet
Thisdocumentcontainsanabridgedsummaryoftheassertionsdescribedintheprevious
document.It’sperfectforprintingandreferencingwhileyoufamiliarizeyourselfwithUnity’s
options.
Unity Configuration Guide
ThisdocumentistheonetoreferencewhenyouaregoingtouseUnitywithanewtargetor
compiler.It’llguideyouthroughtheconfigurationoptionsandwillhelpyoucustomizeyour
testingexperiencetomeetyourneeds.
Unity Helper Scripts
Thisdocumentdescribesthehelperscriptsthatareavailableforsimplifyingyourtesting
workflow.ItdescribesthecollectionofoptionalRubyscriptsincludedintheautodirectoryof
yourUnityinstallation.NeitherRubynorthesescriptsarenecessaryforusingUnity.Theyare
providedasaconvenienceforthosewhowishtousethem.
Unity License
What’sanopensourceprojectwithoutalicensefile?Thisbriefdocumentdescribestheterms
you’reagreeingtowhenyouusethissoftware.Basically,wewantittobeusefultoyouin
whatevercontextyouwanttouseit,butpleasedon’tblameusifyourunintoproblems.
__________________________________________________________________________
UnityProjectThrowTheSwitch.org
MikeKarlesky
MarkVanderVoord

Overview of the Folders
IfyouhaveobtainedUnitythroughGithuborsomethingsimilar,youmightbesurprisedbyjust
howmuchstuffyousuddenlyhavestaringyouintheface.Don’tworry,Unityitselfisverysmall.
Therestofitisjusttheretomakeyourlifeeasier.Youcanignoreitoruseitatyour
convenience.Here’sanoverviewofeverythingintheproject.
●src—Thisisthecodeyoucareabout!ThisfoldercontainsaCfileandtwoheader
files.Thesethreefilesare
Unity.
●docs—You’rereadingthisdocument,soit’spossibleyouhavefoundyourwayintothis
folderalready.Thisiswhereallthehandydocumentationcanbefound.
●examples—ThiscontainsafewexamplesofusingUnity.
●extras—TheseareoptionaladdonstoUnitythatarenotpartofthecoreproject.If
you’vereachedusthroughJamesGrenning’sbook,you’regoingtowanttolookhere.
●test—ThisishowUnityanditsscriptsarealltested.Ifyou’rejustusingUnity,you’ll
likelyneverneedtogoinhere.IfyouaretheluckyteammemberwhogetstoportUnity
toanewtoolchain,thisisagoodplacetoverifyeverythingisconfiguredproperly.
●auto—HereyouwillfindhelpfulRubyscriptsforsimplifyingyourtestworkflow.They
arepurelyoptionalandarenotrequiredtomakeuseofUnity.
How to Create A Test File
TestfilesareCfiles.MostoftenyouwillcreateasingletestfileforeachCmodulethatyouwant
totest.Thetestfileshouldincludeunity.handtheheaderforyourCmoduletobetested.
Next,atestfilewillincludeasetUp()andtearDown()function.ThesetUpfunctioncan
containanythingyouwouldliketorunbeforeeachtest.ThetearDownfunctioncancontain
anythingyouwouldliketorunaftereachtest.Bothfunctionsacceptnoargumentsandreturn
nothing.Youmayleaveeitherorbothoftheseblankifyouhavenoneedforthem.Ifyou’re
usingacompilerthatisconfiguredtomakethesefunctionsoptional,youmayleavethemoff
completely.Notsure?Giveitatry.Ifyoucompilercomplainsthatitcan’tfindsetUportearDown
whenitlinks,you’llknowyouneedtoatleastincludeanemptyfunctionforthese.
Themajorityofthefilewillbeaseriesoftestfunctions.Testfunctionsfollowtheconventionof
startingwiththeword“test”or“spec”.Youdon’tHAVEtonamethemthisway,butitmakesit
clearwhatfunctionsaretestsforotherdevelopers.Testfunctionstakenoargumentsand
returnnothing.AlltestaccountingishandledinternallyinUnity.
Finally,atthebottomofyourtestfile,youwillwriteamain()function.Thisfunctionwillcall
UNITY_BEGIN(),thenRUN_TESTforeachtest,andfinallyUNITY_END().Thisiswhatwill
actuallytriggereachofthosetestfunctionstorun,soitisimportantthateachfunctiongetsits
ownRUN_TESTcall.
__________________________________________________________________________
UnityProjectThrowTheSwitch.org
MikeKarlesky
MarkVanderVoord

Rememberingtoaddeachtesttothemainfunctioncangettobetedious.Ifyouenjoyusing
helperscriptsinyourbuildprocess,youmightconsidermakinguseofourhandy
generate_test_runner.rbscript.Thiswillcreatethemainfunctionandallthecallsforyou,
assumingthatyouhavefollowedthesuggestednamingconventions.Inthiscase,thereisno
needforyoutoincludethemainfunctioninyourtestfileatall.
Whenyou’redone,yourtestfilewilllooksomethinglikethis:
#include“unity.h”
#include“file_to_test.h”
voidsetUp(void){
//setstuffuphere
}
voidtearDown(void){
//cleanstuffuphere
}
voidtest_function_should_doBlahAndBlah(void){
//teststuff
}
voidtest_function_should_doAlsoDoBlah(void){
//moreteststuff
}
intmain(void){
UNITY_BEGIN();
RUN_TEST(test_function_should_doBlahAndBlah);
RUN_TEST(test_function_should_doAlsoDoBlah);
returnUNITY_END();
}
It’spossiblethatyouwillrequiremorecustomizationthanthis,eventually.Forthatsortofthing,
you’regoingtowanttolookattheconfigurationguide.Thisshouldbeenoughtogetyougoing,
though.
How to Build and Run A Test File
Thisisthesinglebiggestchallengetopickingupanewunittestingframework,atleastina
languagelikeCorC++.TheselanguagesareREALLYgoodatgettingyou“closetothemetal”
__________________________________________________________________________
UnityProjectThrowTheSwitch.org
MikeKarlesky
MarkVanderVoord

(whyisthephrasemetal?Wouldn’titbemoreaccuratetosay“closetothesilicon”?).Whilethis
featureisusuallyagoodthing,itcanmaketestingmorechallenging.
Youhavetworeallygoodoptionsfortoolchains.Dependingonwhereyou’recomingfrom,it
mightsurpriseyouthatneitheroftheseoptionsisrunningtheunittestsonyourhardware.
Therearemanyreasonsforthis,buthere’sashortversion:
● Onhardware,youhavetoomanyconstraints(processingpower,memory,etc)
● Onhardware,youdon’thavecompletecontroloverallregisters.
● Onhardware,unittestingismorechallenging
● Unittestingisn’tSystemtesting.Keepthemseparate.
Insteadofrunningyourtestsonyouractualhardware,mostdeveloperschoosetodevelopthem
asnativeapplications(usinggccorMSVCforexample)orasapplicationsrunningona
simulator.Eitherisagoodoption.Nativeappshavetheadvantagesofbeingfasterandeasier
tosetup.Simulatorappshavetheadvantageofworkingwiththesamecompilerasyourtarget
application.Theoptionsforconfiguringthesearediscussedintheconfigurationguide.
Togeteithertowork,youmightneedtomakeafewchangestothefilecontainingyourregister
set(discussedlater).
Ineithercase,atestisbuiltbylinkingunity,thetestfile,andtheCfile(s)beingtested.These
filescreateanexecutablewhichcanberunasthetestsetforthatmodule.Then,thisprocessis
repeatedforthenexttestfile.Thisflexibilityofseparatingtestsintoindividualexecutables
allowsustomuchmorethoroughlyunittestoursystemanditkeepsallthetestcodeoutofour
finalrelease!
__________________________________________________________________________
UnityProjectThrowTheSwitch.org
MikeKarlesky
MarkVanderVoord