`

单元测试 DBFit

 
阅读更多

 

https://github.com/dbfit/dbfit

http://dbfit.github.io/dbfit/docs/reference.html#connect-using-file

http://dbfit.github.io/dbfit/docs/

http://dbfit.github.io/dbfit/docs/getting-started.html#creating-a-new-test-page

 

1. Installing DbFit

DbFit needs the Java Runtime Environment to run - it can be downloaded from the Oracle's Java homepage.
  1. Download DbFit

  2. Unpack dbfit-complete-XXX.zip somewhere on your disk, and run startFitnesse.bat (or startFitnesse.sh on Linux). When FitNesse starts, you should see a command window with this message:

    FitNesse (v20121220) Started...
            port:              8085
            root page:         fitnesse.wiki.FileSystemPage at ./FitNesseRoot
            logger:            none
            authenticator:     fitnesse.authentication.PromiscuousAuthenticator
            page factory:      fitnesse.responders.PageFactory
            page theme:        fitnesse_straight
            page version expiration set to 0 days.
    
  3. Open http://localhost:8085/ and you should see the welcome page. FitNesse is up and running. When you want to shut it down later, just press Ctrl+C in the command window (or close the command window).

    FitNesse.bat failed. What's wrong?

    Read the exception from the command window. If the error mentions versions, check that you have Java 5 or higher installed and that the correct version is being executed when you run java.exe. Run java.exe -version from a command window to see which version of Java is being executed by default. You can run FitNesse with a different Java version either by pointing to the correct JRE in the system executable path (right-click My Computer, select Properties, then go to the Advanced tab, click Environment Variables, and edit the Path variable), or by entering the full path to a different java.exe in startFitnesse.bat.

    If the error report states that there is a security problem or the port is unavailable, enter a different port number instartFitnesse.bat and try again.

Let’s run a quick test to make sure that you have everything set up correctly and that FitNesse can connect to your test database.

2. Creating a new test page

Open http://localhost:8085/HelloWorldTest in your browser. You should see an editor - this is where we’ll create our new test page.

Note Notice that the page name is a CamelCase word.

In FitNesse, all page names have to start with a capital letter, have at least one more capital letter, and all capital letters have to be separated by at least one lowercase letter. FitNesse is really strict about that. This convention causes a lot of headaches for FitNesse newbies, but after a while you'll get used to it. Here are some good page names:
  • HelloWorld
  • TestFluxCapacitor
  • IsPaymentWorkingCorrectly
Here are some page names that will get you in trouble:
  • helloworld (no capital letters)
  • Testfluxcapacitor (just one capital letter)
  • isPaymentWorkingCorrectly (starts with a lowercase letter)
  • TestFCapacitor (two consecutive capital letters)

3. Setting up the environment

In order to load the DbFit extension into FitNesse, your test pages have to load the correct libraries. Replace the contents of the big textbox with the following:

!path lib/*.jar

4. Connecting to the database

DbFit requires two commands to connect to the database. The first line specifies the database type (or test type), and the second defines connection properties. These two lines will typically be the first on every test page. Here is how to connect to a MySQL database:

!|dbfit.MySqlTest|

!|Connect|localhost|dbfit_user|password|dbfit|

Notice the MySqlTest in the first line above. That tells DbFit which type of database driver to use.

Here’s a comprehensive list of available types:

Database DbFit Database Type
Oracle OracleTest
SQL Server 2005 and later SqlServerTest
MySQL MySqlTest
Postgres PostgresTest
Derby DerbyTest
HSQLDB HSQLDBTest
DB2 DB2Test
DB2i DB2iTest
Notice how each command starts with an exclamation mark (!), followed by a pipe symbol (|). Command arguments are then separated by the pipe symbol as well. In FitNesse, tables are used to describe commands, tests, inputs and expected results (you will see the table when the page is saved). In the FitNesse wiki syntax, tables are described simply by separating cells with the pipe symbol. The exclamation mark before the first row of the table is optional, and tells FitNesse not to apply any smart formatting to table contents.

5. Testing a simple query

Now let’s write a simple query test. We will send a request to the database, pull out the result set, and compare it with our expectations. In DbFit, that is done with the Query command. The second cell of the first table row, after the Query keyword, should contain the query we are executing. The second row then contains the result set structure — names of the columns that we want to inspect. You don’t have to specify the full result set here, just the columns that are interesting for a particular test. All rows after that contain expected results. Query disregards result set order — if the order is important you can use OrderedQuery. Here is a simple MySql query:

!|Query| select 'test' as x|
|x|
|test|

The same syntax should work for SQLServer. For Oracle, use this table:

!|Query| select 'test' as x from dual|
|x|
|test|

6. Running the test

Now, click Save. FitNesse will create a new page and display it in your browser. Click on the Test button to make FitNesse run the test. You should see a page telling you that the test passed.

 

 

分享到:
评论

相关推荐

    dbfit:DbFit是一个数据库测试框架,支持轻松的测试驱动的数据库代码开发

    DbFit 测试驱动的数据库开发。 为您的数据库代码编写可读性强,易于维护的单元测试和集成测试。 网站: 。 贡献 有关如何设置测试环境,进行贡献等的详细信息,请参见。 执照 DbFit是根据。

    一步一步学写测试 step by step 写测试

    刚工作的程序员面临写单元测试的问题 这篇文档对单元测试做了详细介绍 方便大家的学习 上手快 看了之后就可以写自己的单元测试了

    Step By Step写测试(书签版).pdf

    《Step By Step写测试》介绍使用 JTESTER 写单元测试,作者吴大瑞,pdf 格式,大小 1.8MB。本书带有 pdf 书签,方便读者阅读。 目录: Jtester的项目配置 1 TestNG测试 1.1 一个简单到不能再简单的测试 1.2 在...

    DbFit-deps:DbFit 依赖的来源

    DbFit-deps DbFit 依赖的来源

    DB Fit-开源

    请注意,该项目已移至GitHub,请参见...DbFit是一组固定装置,使FIT / FitNesse测试可以直接针对数据库执行,从而使开发人员能够以关系形式操作数据库对象。 ,因此使用xUnit风格的工具使数据库TDD变得容易得多。

    jTester 使用指南.pdf

    JTester是一个非常优秀的单元测试框架。早先的jTester中提供了dbFit方式来准备和验证数据库数据,应该来说,这个工具解决了很多问题。实际使用过程中,开发同学反映编辑和准备数据比较麻烦。数据操作错误需要在单独...

    data-tips-tricks:有关数据的提示与技巧

    数据提示和技巧 有关数据的一些技巧和窍门。 有用的文件 ETL项目计划 ...DbFit-测试驱动的数据库开发 建立 Git-开源分布式版本控制系统 贡献 如果您想做出贡献,请阅读CONTRIBUTING.md文件以了解如何做。

Global site tag (gtag.js) - Google Analytics