Tag: 测试

使用Ant运行JUnit测试

我正在尝试运行我的JUnit测试用例,但我一直收到错误: Test com.capscan.accentsWorld FAILED 已创建报告,但未运行测试。 这是我的Ant代码: 这是我的控制台上的输出消息: Buildfile: C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\build.xml create_run_jar: [delete] Deleting directory C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports [mkdir] Created dir: C:\Documents and Settings\Ergun Polat\Desktop\Erguns Content\workspace\AccentsWorld\outputs\reports [junit] Running com.capscan.accentsWorld [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec [junit] Test com.capscan.accentsWorld FAILED [junitreport] Processing C:\Documents and Settings\Ergun Polat\Desktop\Erguns […]

JDBC瘦驱动程序:无效的数据包长度

当我对我的一些Java代码运行自动批量测试时,我遇到了一个奇怪的“无效数据包长度”(这就是拼写错误的方式)错误,我希望有人之前遇到过此错误或者可能指向我正确的方向。 通过JUnitunit testing或从GUI测试我的代码时,我没有遇到此错误。 我在自动批量测试中只遇到此错误。 关于我的批量测试的一点点:对于某些输入,我的代码将运行很长时间(这是预期的),但是为了将结果加速到更合理的时间范围,我正在创建一个新的线程来运行每个个别测试,以便我可以在一些给定的最大经过时间后停止测试。 请注意,测试和实际代码都需要连接到同一个数据库实例才能加载数据。 实际代码使用单个连接从数据库中读取(它不是multithreading的)。 我仍然试图找出测试连接数据库的最佳方法(因此这个问题)。 我的第一个想法是,我正在做一些不友好的事情,因为我关闭我的测试线程以尽早退出运行。 我打电话给被弃用了 threadObject.stop(); 方法,因为我的实际代码不是multithreading的,没有“友好”的方式来杀死内置的线程。在几个(~2-3)停止线程后,我的JDBC连接抛出一个“Invalid Packet Lenght”错误,然后其他测试的“套接字关闭”exception。 我尝试了所有这些相同的结果: 重用实际代码使用的相同连接 创建一个新连接,并为所有测试重用相同的第二个连接 每次我停止()长时间运行的测试时关闭并重新创建测试连接 为每个测试创建一个新连接(这可以工作,直到我最大化我的连接数) 我已经确定了两个连接,“test”和“actual”,“test”连接是抛出exception的连接。 组态: Eclipse 3.4 Java Compliance 1.6 ojdbc14_g.jar JDBC驱动程序 Oracle 9 DB 我究竟做错了什么? 我应该采用不同的方式处理“测试”连接吗? 我是否需要重新构建我的“实际”连接才能运行批量测试? 导致“无效数据包长度”错误的原因是什么?

将项目添加到购物车时,playframework中的function测试失败

我写了一个function测试来检查将商品添加到购物车。对于能够将商品添加到购物车的用户,他需要登录。所以,我创建了一个登录用户的方法和另一种添加商品的方法。之前在测试中的addtocart方法之后,我正在检查购物车内容的大小。当我在开发模式下运行应用程序时,addtocartfunction没有任何问题(我也可以检查数据库 – 这是postgres而不是内存数据库)。addtocart在测试中失败了。 将项目添加到购物车的控制器方法 public static void addItemToCart(Long productId,Long cartId,String quantity) { Product product = Product.findById(productId); ShopCart cart = ShopCart.findById(cartId); int qty = Integer.parseInt(quantity); CartItem cartItem = new CartItem(product,qty); cart.addItem(cartItem); cart.save(); System.out.println(“Controller::addItemToCart()::cart id=”+cart.id+” has=”+cart.cartItems.size()+” items); } 我的测试方法是 @Test public void testUserCanAddItemsToCart() { Fixtures.loadModels(“data.yml”); User user = User.find(“byEmail”,”user@shop.com”).first(); loginAsCustomer(“user@shop.com”,”userpass”); ShopCart usercart = new ShopCart(user); usercart.save(); System.out.println(“BEFORE […]

TestFx入门

我在使用Oracle的JavaFx HelloWorld应用程序使用TestFx时遇到了一些麻烦: public class HelloWorld extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle(“Hello World!”); Button btn = new Button(); btn.setText(“Say ‘Hello World'”); btn.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { System.out.println(“Hello World!”); } }); StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(root, 300, 250)); […]

FEST:在执行任何操作之前等待GUI加载

@Before public void setUp() { Robot robot = BasicRobot.robotWithCurrentAwtHierarchy(); ApplicationLauncher.application(“myApp”).start(); Pause.pause(5, TimeUnit.SECONDS); frame = WindowFinder.findFrame(“frame0”).using(robot); JTableFixture table = frame.table(new GenericTypeMatcher(JTable.class) { @Override protected boolean isMatching(JTable table) { return (table instanceof myTreeTable); } }); } 这段代码效果很好。 如果我们删除5秒暂停,则找不到表,因为应用程序加载它需要几秒钟。 我想知道是否有更清洁的方法。 我在ApplicationLauncher之后尝试使用robot.waitForIdle()(我猜一旦EDT为空,一切都已加载),但它无法正常工作。 我知道暂停可以使用某些条件作为何时停止的事件,但我不明白如何编写它,因为JavaDoc和官方文档很差。 Pause.pause(WaitForComponentToShowCondition.untilIsShowing(frame.component())):我需要一个组件,如果我通过包装器框架它不起作用。 我无法通过这张桌子,因为这正是我正在等待的。 我明白我应该使用ComponentFoundCondition,但我不明白! 我厌倦了: ComponentMatcher matcher = new GenericTypeMatcher(JTable.class) { @Override protected boolean isMatching(JTable table) { […]

如何通过Junit获得成功并暂停?

@Test (expected=TimeoutException.class,timeout=1000) public void fineForFiveSeconds() { foo.doforever(); fail(“This line should never reached”); } 这是我的测试代码。 我想要的是运行doforever()一段时间然后让测试成功。

Espresso onData在视图上执行“加载适配器数据”时出错

我有一个应用程序,有ListView,我想找到LinearLayout,id = order_untake_jijia_listview_jia 代码是: onData(withClassName(endsWith(“ListView”))) .inAdapterView(allOf(withId(R.id.order_untake_jijia_listview_ll), hasSibling(withText(“9.0”)))) .atPosition(0).onChildView(withId(R.id.order_untake_jijia_listview_jia)); dataInteraction.perform(ViewActions.click()); 但我有错误: Error performing ‘load adapter data’ on view ‘(with id: com.edaixi:id/order_untake_jijia_listview_ll and has sibling: with text: is “9.0”)’. Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints: (is assignable from class: class android.widget.AdapterView […]

用于在Java Play中测试的HTTP上下文! 2.0.2

我们正在尝试为视图编写测试,但其中一些需要会话变量才能正确呈现。 这是标准测试的样子: @Test public void indexTest() { running(fakeApplication(), new Runnable() { public void run() { Content html = views.html.index.render(loginForm); assertThat(contentType(html)).isEqualTo(“text/html”); assertThat(contentAsString(html)).contains(“log in”); } }); } loginForm是我们在测试类中声明的模拟表单。 但是,当我们尝试运行此测试时,我们会收到以下错误: ‘这里没有可用的HTTP上下文’ 我们尝试使用testServer并尝试从请求到该服务器获取http上下文,但无济于事。 谢谢 :-) 编辑 @nico_ekito 这是我的loginForm周围的代码: Form loginForm = Controller.form(Login.class); 但是,我认为问题在于被调用的控制器,因为视图不使用任何会话属性。 然而,authenticate()方法(在控制器中,我相信当表单提交到视图时)会使用会话。

指定dependsOnMethods时,testng未按优先级顺序运行

每当我们在@Test注释方法上指定priority和dependsOnMethods时,测试方法的执行顺序不是根据优先级。 为什么会这样? 以下是演示该问题的测试类: package unitTest.TestNGTestCases; import org.testng.annotations.Test; public class TestNGTest1 { @Test(priority=1) public void t1() { System.out.println(“Running 1″); } @Test(priority=2,dependsOnMethods=”t1”) public void t2() { System.out.println(“Running 2″); } @Test(priority=3,dependsOnMethods=”t2”) public void t3() { System.out.println(“Running 3”); } @Test(priority=4) public void t4() { System.out.println(“Running 4”); } } 实际产量: Running 1 Running 4 Running 2 Running 3 =============================================== All […]

是否可以更好地替代Groovy for Java集成测试?

我打算使用其编程接口测试我的基于Java的Web应用程序。 为此,我打算使用他们的RMI / WebService接口调用我的会话bean,并检查他们支持的服务是否正确。 为此,我需要一种脚本语言: 调用我的RMI / WebService接口 执行SQL语句(例如,首先清理DB) 有一个简单的流量控制(循环,条件等) 容易理解。 我可能会要求我的非程序员编写测试脚本 我打算将Groovy用于此目标。 Groovy有更好的建议或替代方案吗? 编辑1 在答案中提到的其他介绍的Groovy替代品是JRuby和RSpec。 网上有没有比较?