- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我问是因为我在 Google 中找到的所有示例都与 Fitnesse 教程中的相同:对内存中的列表或数组的非常简单的查询,而不是真正的数据库。
是的,Fixtures 永远不必处理这个问题,但是如果我什至无法在“API”的模拟中连接到 DB,我应该如何测试我的 fixtures?
我试图模拟的是从 FitNesse Fixture 调用以 Java 查询 PostgreSQL 数据库/表。在这个简单的示例中,我试图从一个表中的一行中获取至少一列。当我执行代码时,它会自行完美运行。问题是当试图通过夹具从 Fitnesse 执行时。调用 JDBC 驱动程序时,它总是因 ClassNotFoundException 而失败。单独运行代码不会发生这种情况。
这是执行查询的代码:
package queriespackage;
import java.sql.*;
public class testQuery01 {
public static Connection openDBConnection(){
Connection connectionString = null;
try {
String dbhost = "SOMEURL";//Redacted
String port = "SOMEPORT";//Redacted
String dbname = "THEDBNAME";//Redacted
String username = "SOMEUSER";//Redacted
String password = "SOMEPASSWORD";//Redacted
String driverJDBC = "org.postgresql.Driver";
Class.forName(driverJDBC);
connectionString = DriverManager.getConnection("jdbc:postgresql://" + dbhost + ":" + port + "/" + dbname,username,password);
connectionString.setAutoCommit(false);
} catch (SQLException e) {
e.printStackTrace(System.err);
System.exit(0);
} catch (Exception e) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
};
return connectionString;
};
public static ResultSet executeQuery(Connection connectionString, int intAccountId) throws SQLException{
Statement querySession = connectionString.createStatement();
//The query string
String queryString = "SELECT DISTINCT "
+ "account_search.account_id,"
+ "account_search.account_name"
+ " FROM account_search "
+ " WHERE"
+ " account_search.account_id = "+ intAccountId
+ "LIMIT 1";
ResultSet queryResult = querySession.executeQuery(queryString);
return queryResult;
};
public static String processQueryResult(ResultSet queryResult) throws SQLException{
String strQueryValueReturned = null;
while (queryResult.next()) {
strQueryValueReturned = queryResult.getString("account_name");
};
return strQueryValueReturned;
};
public static boolean closeDBConnection(Connection connectionString){
try {
if(connectionString!=null){
connectionString.close();
}
} catch (SQLException e) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
};
return true;
};
public static String testQuery(int intAccountId) throws SQLException, ClassNotFoundException{
boolean bolConnectionStatus = false;
String strValueReturned = null;
Connection connectionString = openDBConnection();
if(connectionString != null){
ResultSet qryQueryResult = executeQuery(connectionString, intAccountId);
strValueReturned = processQueryResult(qryQueryResult);
bolConnectionStatus = closeDBConnection(connectionString);
if(!bolConnectionStatus){
System.exit(0);
}
}else{
System.exit(0);
};
return strValueReturned;
};
};
如果我向该代码添加 Main 方法,将“intAccountId”的参数值传递给它,它会成功返回帐户“account_name”的名称,只是正如预期的那样。
现在这是 FitNesse 测试应该调用的 Fixture:
package fixturespackage;
import java.sql.SQLException;
import queriespackage.testQuery01;
public class testFixture01{
private int Int_AccountId;
//Fixture Constructor (setter)
public testFixture01(int Int_AccountId){
this.Int_AccountId = Int_AccountId;
};
public String query() throws SQLException, ClassNotFoundException{
return testQuery01.testQuery(Int_AccountId);
};
};
正如 FitNesse 指南所说,必须有一个“查询”方法,它对数据库中的接口(interface)进行实际调用。我不得不添加一个构造函数而不是“setter”,因为 FitNesse 实际上需要它:“Could not invoke constructor for fixturepackage.testFixture01”
这是 FitNesse 页面:
!***> System Variables
!define TEST_SYSTEM {slim}
!path C:\FitnessTest\bin
*!
|Query: fixturespackage.testFixture01|21 |
|Str_AccountName |
|SomeName |
这是我的 BuildPath 的屏幕截图,因此您可以看到我有适用于 Java 8、JDK 1.8、JRE 1.8 的 JDBC 库......并且项目中包含“org.postgresql.Driver.class”。
这是我从 FitNesse 运行时收到的错误:
这是我在使用 Inspect 工具调试 FitNesse 失败的行时得到的错误:
... 是的,我还尝试通过硬编码 JDBC 的名称:
我在 FitNesse 指南和 Google 上搜索了很多真实生活中的例子。
FitNesse 指南可能内容广泛,但老实说,它充满了“脏话”、不切实际和不完整的示例,并且遗漏了很多信息。
所以,再问一次,有没有人使用 FitNesse 进行过真实生活测试,提出问题,这可以帮助我找出我做错了什么?
最佳答案
我不得不承认我只用 FitNesse 做过有限的数据库测试,但我已经使用它们(查询 DB2)。我没有使用查询表(或编写自己的固定装置来查询),而是使用了 jdbcslim结合脚本表和场景。
无法找到驱动程序类这一事实表明,虽然 jar 存在于您的 IDE 的类路径中,但当 FitNesse 运行您的夹具代码时它不可用。
我注意到您将类路径指定为 wiki 中的单个目录。在 Java 中,这意味着所有类文件都应该在该目录中(作为 .class 文件,在它们定义的包的正确子目录中)。它不会在该目录中获取任何 jar(或 zip)。您是否将数据库驱动程序的 jar 解压到该目录?如果没有,您需要使用数据库驱动程序添加指向 jar 的 !path
行(因此包含文件名的整个路径)。
现在列出您需要的每个 jar 很快就会变得很麻烦,因此您也可以使用通配符。我倾向于将我需要的所有 jars 复制到一个目录,该目录还包含我的 fixture .class 文件,并添加一个 !path
行加载该目录中的所有 jars。因此,如果您还将数据库驱动程序复制到您提出问题的目录中,您可以确保它和您自己的固定装置可通过
!path C:\FitnessTest\bin
!path C:\FitnessTest\bin\*.jar
关于java - 有没有人做过查询 REAL 数据库的 FitNesse 测试?我无法使 Fitnesse 连接成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54372624/
我有一个关于 JavaScript 语法的问题。实际上,我在自学 MEAN 堆栈教程时想出了编码(https://thinkster.io/mean-stack-tutorial#adding-aut
在我的书中它使用了这样的东西: for($ARGV[0]) { Expression && do { print "..."; last; }; ... } for 循环不完整吗?另外,do 的意义何
我已经编写了读取开关状态的代码,如果按 3 次 # 则退出。 void allkeypadTest(void) { static uint8_t modeKeyCount=0; do
因此,对于上周我必须做的作业,我必须使用 4 个 do-while 循环和 if 语句在 Java 中制作一个猜谜游戏。我无法成功完成它,类(class)已经继续,没有为我提供任何帮助。如果有人可以查
int i=1,j=0,n=10,k; do{ j+=i; i<<1; printf("%d\n",i); // printf("%d\n",12<<1); }while
此代码用于基本杂货计算器的按钮。当我按下按钮时,一个输入对话框会显示您输入商品价格的位置。我遇到的问题是我无法弄清楚如何获得 do ... while 循环以使输入对话框在输入后弹出。 我希望它始终恢
当我在循环中修改字符串或另一个变量时,它的条件是否每次都重新计算?或者在循环开始前一次 std::string a("aa"); do { a = "aaaa"; } while(a.size<10)
我刚刚写了这个,但我找不到问题。我使用代码块并编写了这个问题 error: expected 'while' before '{' token === Build finished: 1 errors
do { printf("Enter number (0-6): ", ""); scanf("%d", &Num); }while(Num >= 0 && Num 表示“超过”,<表
我有一个包含 10 个项目的 vector (为简单起见,所有项目都属于同一类,称其为“a”)。我想要做的是检查“A”不是 a) 隐藏墙壁或 b) 隐藏另一个“A”。我有一个碰撞函数可以做到这一点。
嗨,这是我的第二个问题。我有下表 |-----|-------|------|------| |._id.|..INFO.|.DONE.|.LAST.| |..1..|...A...|...N..|.
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: Why are there sometimes meaningless do/while and if/e
来自 wikibook在 F# 上有一小部分它说: What does let! do?# let! runs an async object on its own thread, then it i
我在 Real World Haskell 书中遇到了以下函数: namesMatching pat | not (isPattern pat) = do exists do
我有一个类似于下面的用例,我创建了多个图并使用 gridExtra 将它们排列到一些页面布局中,最后使用 ggsave 将其保存为 PDF : p1 % mutate(label2
当我使用具有 for 循环的嵌套 let 语句时,如果没有 (do (html5 ..)),我将无法运行内部 [:tr]。 (defpartial column-settings-layout [&
执行 vagrant up 时出现此错误: anr@anr-Lenovo-G505s ~ $ vagrant up Bringing machine 'default' up with 'virtua
# ################################################# # Subroutine to add data to the table Blas
我想创建一个检查特定日期格式的读取主机。此外,目标是检查用户输入是否正确,如果不正确,则提示应再次弹出。 当我刚接触编程时,发现了这段代码,这似乎很合适。我仍然在努力“直到” do {
我关注这个tutorial在谷歌云机器学习引擎上进行培训。我一步一步地跟着它,但是在将 ml 作业提交到云时我遇到了错误。我运行了这个命令。 sam@sam-VirtualBox:~/models/r
我是一名优秀的程序员,十分优秀!