So I can test code that uses a database using PHPUnit, I just installed the DbUnit extension using Composer, and I get the following message:
Package phpunit/dbunit is abandoned, you should avoid using it. No
replacement was suggested.
I've seen the issue on the extension being abandoned, and people talk of rolling your own database testing code, but they don't go into any more details. Is there a recommended way to test database code using PHPUnit, or does anyone know of any examples?
(I did open an issue and asked the author of PHPUnit this, but his reply was quick and to the point - "No, there is not.") :-/
Related
I am using Dropwizard and I want to unit test my DAO classes. I saw a bunch of examples online but they seem to be using DAOTestRule which I cannot find in 0.9.2 which is what we use here at work.
None of the blogs explain what is the replacement or why it was deprecated in the first place. The official documentation doesn't detail anything either. How can I go about testing my DAO and setting up an in-memory database for Dropwizard Testing?
See issue Can't find DAOTestRule.java at dropwizard-testing maven 1.0.5 version jar.
Answer
That's because it's only available in Dropwizard 1.1.x and later.
https://github.com/dropwizard/dropwizard/commits/master/dropwizard-testing/src/main/java/io/dropwizard/testing/junit/DAOTestRule.java
See also this issue. Looks like it was also back-ported to 1.0.6.
What is the alternative?
Update your DW version.
There are a lot of resources out there for unit testing in dart using the old unittest library, but I can't find much about the test library, which was just released at the end of last year.
In unittest you could call useHtmlConfiguration() or useHtmlEnhancedConfiguration() that would serve up test results on localhost:8081 or whatever port you used with pub serve. The new library doesn't seem to have that, or at least it's not well documented. So my first question is: Is there a good way to run unit tests in the browser by typing localhost:8081 like with the old library, or does everything have to be done from the terminal?
I'm able to run the tests with pub run test:test --pub-serve=8081 -p firefox, but I'm just wondering if anyone has some "best practices" with this library to share since it's so new.
The test package only prints progress and test results to the console. WebStorm/IntelliJ in the most recent version provide a GUI API for running the tests.
The readme https://pub.dartlang.org/packages/test is quite comprehensive about how to use the package.
I wouldn't say the new test package is so new anymore. I'm using it since more than a year AFAIR and almost all packages maintained by the Dart team and probably most others are already migrated to the new test package.
I am Unit testing on the client side of a GWT+SmartGWT application.
First I tested with GwtTestCase. Too long for unit testing a huge application. GwtTestSuite doesn't help. It still takes too much time to execute. (more, it asked me to start a browser when it's testing)
Then gwt-test-utils : Great framework. Sadly, my javassist version is 3.5 and need at least the 3.11. Javassist is used by gilead so I can't touch this. So, no gwt-test-utils...
I saw Selenium. That's just great. With htmlunit driver, it's fast and useful. Simplest way to test a webapp. Problem here is SmartGWT generates it's own IDs when it generates the web page. So I can't get the TextItems and fill them since those IDs are constantly changing. I found that it could be solved by using setID() before the initialization of the widget. But that's the ID of the scLocator and not an HTML ID. Selenium doesn't want to work with scLocator.
=> Is there a simple way to accept scLocator with Selenium ?
(And when I say simple, it must be simple... I'm not a specialist in Java...)
Could someone help me to unit test the application ? It's coded in Java, it's huge and I have to cover ~70% of the code (25k lines of code)
Some more specs :
Maven is used to compile.
I'm not touching at the server side.
Tests must be faster than GwtTestCase and Suite :/
I hope my problem is clear, I'm not a native english so sorry for mistakes I may do :x
We provide Selenium extensions and a user guide for them in the SDK, under the "selenium" directory at top level.
If you download 3.1d (from smartclient.com/builds) there's even more documentation including some samples for JUnit.
Do not use ensureDebugId() (won't have an effect at all). Never try to work with DOM IDs (won't work).
Best practices information in the Selenium user guide explains when you should use setID().
I found that it could be solved by using setID() before the
initialization of the widget. But that's the ID of the scLocator and
not an HTML ID.
Why don't you try:
widget.ensureDebugId("some-id");
From the Java docs for ensureDebugId():
Ensure that the main Element for this UIObject has an ID property set,
which allows it to integrate with third-party libraries and test tools
< defaultUserExtensionsEnabled>true< /defaultUserExtensionsEnabled>
< userExtensions>[path to user-extensions.js]< /userExtensions>
There we go. I managed to make it work. (With the selenium-maven-plugin in the < configuration> tag)
Thanks for your help though.
I'm working with Symfony + Doctrine + PHPUnit, with NetBeans IDE. Here' my current approach to unit testing.
setUp() function loads the test fixtures from .yml files
tearDown() function delete all data from models. this is done by looping through an array of all my models' names to something like Doctrine_Query::delete($modelName)->execute()
This seems to work, but i'm just curious if this is the correct way to do it. I am essentially clearing all tables after each test function by specifying the models/tables to 'delete all' from.
Q1: I am just wondering if this is the correct way...
Q2: this works nicely in Netbeans IDE, but does not seem to work via "./symfony test:unit". am i missing something or the CLI just works with lime?
./symfony test:unit runs symfonys own test suite that is using lime as a test framework, and not phpUnit.
And netbeans uses phpUnit for its integrated test support. hopefully netbeans will add test suport for symfony test suite in their incomming symfony suport in netbeans 6.8
If you want to use phpunit with symfony check out: PHPUnit plugin Just a note that this only works with 1.2.x it seems, for 1.4.x which is what I'm currently using at work check out: Another PHPUnit plugin this last one is in beta, but it works for 1.4.x according to the author, I'll be trying it out soon, so if I can remember, I'll come back here and throw up my findings. It's honestly not to hard to back out if you don't want to install it, so trying it is easy.
If you happen to try it, please post your findings, I'd be really interested in hearing your thoughts. I'm finding lime to be lame (HAH!) as it just makes mocking a chore.
I'm trying it externally with PHPUnit, no plugin. I'm using Doctrine. I am having quite a problem. If I run ONE PHPUnit (written by me) tes method, it's great. The second one, not so good. It may be the way I'm using Doctrine. It seems like even though I delete everything from the database (between PHPUnit Method calls) and restore the fixtures file, all in the setup(), DOCTRINE remebers previous values.
Doesn'jt matther whether I flush the connection, unset the parent object that is being erroneiously 'remembered', refreshRelated() etc, I still get old values when I do the first assignment to a relationship.
$parent=new ParentType;
//set parent values.
$child=new ChildType
//set child values
$child['Parent']=$parent;
$child->save();
The database is reflecting everything fine, it's Doctrine in PHPUnit that's not working. I haven't tried it OUT of PHPUnit yet, after all, test before use, right? But I may have to do that and see if it's Doctrine or PHPUnit
I just recently started learning the Scala language and would like to do it in TDD-way. Could you share your experiences on the unit testing frameworks there are for Scala and the pros/cons of them.
I'm using IntelliJ IDEA for Scala development, so it would be nice to be able to run the tests with IDE-support.
Have you looked at ScalaTest ?
I've not used it, but it comes from Bill Venners and co at Artima, and consequently I suspect it'll do the job. It doesn't appear to have IDE integration, however.
This blog entry is a little old, but suggests that TestNG is the best option for testing Scala. TestNG will certainly have IDE integrations.
EDIT: I've just realised that I wrote this answer in 2009, and the world has moved on (!). I am currently using ScalaTest, the IDE integration works fine, and I can strongly recommend it. In particular the matcher DSL works very nicely
I'm the author of specs. If you're a Intellij user, I advise you to mix-in in the org.specs.runner.ScalaTest trait to your specification and run it as a ScalaTest suite.
If you have any issue with that, or anything else feel free to send a message to the specs-users mailing list.
You could also check out Specs it's fairly complete and IIRC is heavily used as part of Lift.