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
Getting Started
1. Installing DbFit
-
Unpack
dbfit-complete-XXX.zip
somewhere on your disk, and runstartFitnesse.bat
(orstartFitnesse.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.
-
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
. Runjava.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 differentjava.exe
instartFitnesse.bat
.If the error report states that there is a security problem or the port is unavailable, enter a different port number in
startFitnesse.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.
- HelloWorld
- TestFluxCapacitor
- IsPaymentWorkingCorrectly
- 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:
Oracle | OracleTest |
SQL Server 2005 and later | SqlServerTest |
MySQL | MySqlTest |
Postgres | PostgresTest |
Derby | DerbyTest |
HSQLDB | HSQLDBTest |
DB2 | DB2Test |
DB2i | DB2iTest |
!
), 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的核心理念是通过测试来驱动数据库的开发,这有助于在早期发现潜在问题,提高...
### 单元测试入门与实践 #### 一、引言 单元测试是在软件开发过程中非常重要的一环,它有助于确保代码质量、减少后期维护成本,并帮助开发者更好地理解代码逻辑。对于初入职场的程序员来说,掌握如何编写有效的...
- **基础概念**:TestNG是一个强大的测试框架,用于Java应用程序的单元测试和功能测试。 - **简单测试示例**:通过`@Test`注解标识测试方法,如清单1所示,演示了如何对`StringUtils`类进行简单的测试。 - **Eclipse...
DbFit-deps DbFit 依赖的来源
请注意,该项目已移至GitHub,请参见...DbFit是一组固定装置,使FIT / FitNesse测试可以直接针对数据库执行,从而使开发人员能够以关系形式操作数据库对象。 ,因此使用xUnit风格的工具使数据库TDD变得容易得多。
JTester是一个非常优秀的单元测试框架。早先的jTester中提供了dbFit方式来准备和验证数据库数据,应该来说,这个工具解决了很多问题。实际使用过程中,开发同学反映编辑和准备数据比较麻烦。数据操作错误需要在单独...
数据提示和技巧 有关数据的一些技巧和窍门。 有用的文件 ETL项目计划 ...DbFit-测试驱动的数据库开发 建立 Git-开源分布式版本控制系统 贡献 如果您想做出贡献,请阅读CONTRIBUTING.md文件以了解如何做。
- **测试工具**:JUnit、JUnit Perf、EasyMock、JMock、FIT、Fitnesse、DBFit、Selenium、JMeter、JAMon。 - **持续集成工具**:CruiseControl、Hudson。 - **项目管理工具**:VersionOne、JIRA、Bugzilla、...