Fixture Code
Packageeg;ImportOrg.joda.time.DateTime; Public classJodatime {intYear ; PublicString GetCurrentTime () {datetime datetime=NewDateTime (); returnstring.valueof (dateTime); } Public intgetYear () {datetime datetime=NewDateTime (); year=datetime.getyear (); returnYear ; } PublicString getstringyear () {datetime datetime=NewDateTime (); returnstring.valueof (Datetime.getyear ()); } Publicstring Getyearandmonth (String string) {datetime datetime=NewDateTime (); returnString.valueof (Datetime.getyear ()) + string.valueof (datetime.getdayofmonth () +string); }}
Table code:
!***< Hidden!*< Classpath setup! define Test_system {slim}!path lib/*. jar*! " Import the background code package name "'!| here Import | | eg | | fitnesse.fixtures|*! "" Test Script "'!| Script|joda Time | | Check |get current time| | | Check|get year| | | $v =|get year| | $s =|get string year| | Check | Get Year and Month | 567| | | Check | Get Year and Month | $s | |
Table View and Result:
-------------------------------------------------------------------------------------------
Preparatory work:
(a) Import third-party jar packages, used here to Joda-time-2.3.jar
1. First put the Joda-time-2.3.jar into the. \fitnesse-master\lib below
2. In eclipse, follow the edit build Path
3. Modify the Build.xml file in the FitNesse project, below the yellow bottom section.
....<Targetname= "Compile-server"depends= "Stamp-version, resolve"Description= "Compile FitNesse sources"> <mkdirdir= "${classes.dir}" /> <Ivy:cachepathPathid= "Compile.classpath"conf= "Default"/> <JavacSrcdir= "${src.dir}"Destdir= "${classes.dir}"Debug= "true"Source= "${min.java.version}"Target= "${min.java.version}"Includeantruntime= "false"encoding= "UTF-8"> <Classpath> <pathelement Path = "{Lib.dir}/joda-time-2.3.jar"/> <PathrefID= "Compile.classpath"/> </Classpath> </Javac> <CopyTodir= "${classes.dir}"> <Filesetdir= "${src.dir}"> <includename= "fitnesse/resources/**" /> <includename= "**/*.properties" /> </Fileset> </Copy> </Target>.... <Targetname= "Retrieve"depends= "Resolve"Description= "Copy dependencies to lib/, mainly for acceptance tests and IDE S"> <!--<delete dir= "${lib.dir}"/>--> <Ivy:retrievepattern= "${lib.dir}/[artifact". [ext] "conf= "Standalone,default,test" /> </Target>....
4. Create a new Jodatime class in the FitNesse project eg, the code is the fixture code above
5. Open the command line, enter the FitNesse home directory, enter the ant run, and start the compilation
6. Create a new testpage in FitNesse, click the Edit button, enter the content (you can directly copy the table code above)
7. After clicking Save, click the Test button to start the test.
A simple example of FitNesse