Hands on training on DbFit Part-II


Published on

Published in: Education, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Hands on training on DbFit Part-II

  1. 1. Database Unit TestingwithDbFitPresented byMd. Babul MirdhaSenior Software EngineerLeads Corporation LtdPart-II
  2. 2. Working mode of DbFit Fixtures• DbFit fixtures can work in two modes:– Flow Mode– Standalone Mode
  3. 3. Flow mode:– a DatabaseTest fixture controls the whole pageand coordinates testing.– automatically rolls back the current transaction atthe end to make tests repeatable,– provides some additional options such asInspections of stored procedure error results.
  4. 4. Standalone:– In this case, we are responsible for transactionmanagement.– This enables you to have more control over thedatabase testing process
  5. 5. Connecting in flow mode• For Standard Connection:– Use the Connect method to initialise the databaseconnection.– Pass the server (optionally followed by the instancename), username, password and the database nameas arguments.!|dbfit.SqlServerTest|!|Connect|LAPTOPSQLEXPRESS|FitNesseUser|Password|TestDB|– If you are connecting to a default database, you can omit the fourth parameter.
  6. 6. Connecting in flow mode• For Non-Standard Connection:– use non-standard connection properties, or initialize your connectiondifferently (for example, using Windows integrated authentication),call Connect with a single argument — the full .NET connection string.!|dbfit.SqlServerTest|!|Connect|data source=Instance;userid=User;password=Pwd;database=TestDB;|– For flow mode to work correctly, the SqlServerTest fixture must be thefirst one on the page — not even import can be before it.– This is why we explicitly specify the namespace.
  7. 7. Transaction management- In flow mode• The current transaction is automatically rolled back at the end of the page.• If we want to commit it to make changes permanent, put the Committable into the page.• There are no arguments or additional parameters — the table contentscontain just this one word.• Likewise, you can roll back manually in your test using the Rollback table.!|dbfit.SqlServerTest|!|Connect|LAPTOPSQLEXPRESS|FitNesseUser|Password|TestDB|………|Commit|Or|Rollback|
  8. 8. Connecting in standalone mode|import||dbfit.fixture|!|DatabaseEnvironment|sqlserver||Connect|LAPTOPSQLEXPRESS|FitNesseUser|Password|TestDB|• Notice that there is no space betweenDatabaseEnvironment and Connect — they have to bein the same table.• Because we are not using flow mode, we can use theimport fixture as well.• Most DbFit fixtures are in dbfit.fixture namespace, so itis good practice to include this namespace.
  9. 9. Transaction management-In standalone mode• Use the DatabaseEnvironment fixture again, but do not specify a fixture argument.• This tells the DatabaseEnvironment to use the current default database connection, withoutattempting to initialise it.• Call Commit or Rollback in the second row.|import||dbfit.fixture|!|DatabaseEnvironment|sqlserver||Connect|LAPTOPSQLEXPRESS|FitNesseUser|Password|TestDB|………!|DatabaseEnvironment||Commit|Or!|DatabaseEnvironment||rollback|• It is a very good idea to put this table in a TearDown page for your test suite when you usestandalone DbFit fixtures.• This will make sure that your tests are repeatable.
  10. 10. DemoFlow Mode&Stand Alone Mode
  11. 11. More AboutWiki
  12. 12. Wiki ActionsAction Name Command To UrlEdit this page url?editCreate a new page directlycurrent-url.NewPageNameorcurrent-url.NewPageName?editTest this page url?testSuite test this page url?suiteSet properties of this page url?propertiesSee versions of this page url?versionsRefactor this page url?refactorSearch pages from here url?searchFormWhere is this page referenced? url?whereUsedDebug this test page url?debugSuite test this page with a suite filter"passing"url?responder=suite&suiteFilter=passing
  13. 13. Includes & InformationalTimestamp !lastmodifiedTimestamp !todayHelp text !helpContents List !contentsContents Tree !contents -RContents Sub-tree !contents -R[nn]Contents List - Graceful !contents -gContents List - Properties !contents -pContents List - Suite Filters !contents -fContents List - Help Text !contents -h
  14. 14. Include Page!include AnyPagePath expanded border!include -c AnyPagePath collapsed border!include -seamlessAnyPagePathno border!include -setup AnyPagePath appears like SetUp!include -teardownAnyPagePathappears like TearDown| !include AnyPagePath | in a table cell
  15. 15. Picture Insert!img url-to-image-file in-line!img-l url-to-image-file image left-justified, text wraps on right!img-r url-to-image-file image right-justified, text wraps on the left!img[-l |-r] url-to-image-fileas a clickable link
  16. 16. Fixture Symbol• Symbols are global variables that can be accessed using a simple syntax.• Symbols are stored in a static collection inside the Fixture class• To store a value of an output column into a symbol named player, write >>player into the cell.• To read a symbol value, and store it into an input column, use <<player.• Think of << and >> as arrows pointing the way.!|Insert|users||username|name|userid?||pera|Petar Detlic|>>peraid||Mika|Mitar Miric|>>mikaid|!3 Confirm that IDs are the same as in the database!|Ordered Query|Select * from users||username|name|userid||pera|Petar Detlic|<<peraid||Mika|Mitar Miric|<<mikaid|16
  17. 17. What is the scope of a symbol?• Symbols are stored in a static collection insidethe Fixture class.• so their scope is global from the point wherethey are defined until the test runner stops.• A symbol scope will effectively extend to allpages executed after the page where it isdefined.
  18. 18. Markup variableVariablesVariable Definition!define name {value}!define name (value)!define name [value]Variable Usage ${name}
  19. 19. What is the difference between variables and symbols?• Markup variables are processed by the wiki, before running tests.• Symbols are processed by the FIT engine while running tests.• Because of that, variables can be used even as a part of cell content.• you can use a markup variable:!define Markup {reader}|StringFixture||field|field?||acrobat ${Markup}|acrobat reader|• But this will not work:|Query | select ‘reader as Symbol|| Symbol?||>>MySymbol||StringFixture||field|field?||acrobat << MySymbol|acrobat reader|• Symbols are also available to fixtures at runtime, and variables are not.
  20. 20. Wiki and SubWiki Wiki: A normal Wiki is a collection of pages with a flat structure. All the pages are peers. You add a top-level page simply by placing a WikiWord on an existing top-level page,and then clicking on the ? SubWiki: FitNesse allows you to create Sub Wikis. Each Wiki page can be the parent of an entire new Wiki. You create a sub wiki page by ParentPage.SubPage (or the shortcut ^SubPage), and thenclicking on the ?… WikiparentSubWiki 1SubWiki 2http://fitnesse.org/FitNesse.UserGuide.SubWiki
  21. 21. Sub Wikis and Test suites• Each wiki (and sub wiki) can have its own– ClassPath– PageHeader, PageFooter– SetUp, TearDown– SuiteSetup, SuiteTearDown• Test Suites– A Test Suite executes all tests in the sub wiki (tree of pages)– SetUp and TearDown pages are invoked for each page of the suite– To wrap an entire suite, define the operations on pages SuiteSetUpand SuiteTearDown21
  22. 22. 22WikiSub-wikiRemember to initially create the first page
  23. 23. Demoon Wiki & SubWiki23
  24. 24. WikiImport• What is WikiImport?– allows you to import an entire wiki or subwikifrom another FitNesse site.– All of the pages from the remote wiki will becopied to your local FitNesse and become part ofyour local wiki.
  25. 25. • Why should I use WikiImport?– In a development environment it is most practical tohave a main FitNesse server where all the tests aremaintained and new tests are added.– However, it is not practical for all the developers torun the tests on one server.– Therefore each developer should have a FitNesseinstallation in their development environment.– The test pages from the main server get imported byeach developer so they can execute the most recenttests against their current code base.
  26. 26. How do I use WikiImport?– Create a page or use an existing page that willcontain the imported wiki.– Open the properties view of this page.– There is a form title Wiki Import.– Supply the URL to the remote wiki that youd liketo import– Submit the form.
  27. 27. Update imported wiki• Once a wiki has been imported, it may beupdated at any time.– Open the properties view of the importing page orany imported page.– There will be a button in the Import Wiki section.– Clicking this button initiate an update of all theimported pages beneath the currently selectedpage.
  28. 28. New Edit Buttons -WikiImport• Once you have imported a wiki, the Edit button will beturned off and two new edit buttons will be added:– Edit Locally and– Edit Remotely.• Edit Locally– behaves just like the Edit button that youve used all along.• Edit Remotely– allows you to easily edit the page from where the contentis being imported.
  29. 29. Automatic Update Option - WikiImport• Click on the page properties, youll see a checkbox that says:• Enabling this option will kick off an update forany test page prior to execution.• Child pages will inherit this option from parentpages, which means you need only set on theroot of you test hierarchy.
  30. 30. DEMOConfigure & Install & Local ServerImport wiki
  31. 31. Thank You!
  32. 32. Q & A