Where is the SubSonic 3 Test Database "SubSonic"? - subsonic3

I may be a little dense at times but where do I get the SubSonic database referenced by the SubSonic 3 test project?

The database is created on the fly using our migrations stuff. So - just create a DB called "SubSonic" and the tests do the rest. See the Setup() routine to see how this works - the tables are created on every test.

You can usually find everything you need in SubSonic's github. I think the DbScripts directory probably has what you need.
http://github.com/subsonic/SubSonic-3.0/tree/master

Related

Suggestion on Creating Unit test for database layer

thank you for reading my question.
I was just wondering about how shall i create unit tests for existing database layer. as of now my project has existing unit tests but no unit test is written for database layer or any function which inserts / updates / deletes data from database.
We are using Microsoft tests. One approach I think here is
1) We shall create database on the fly i.e. mdf file and we will keep our defaults values ready in it and in our setup method(Nunit) or initialize method(MS tests) we will mock the objects and dump the dummy data into tables.
Also we are not using any mocking framework. So i am all confuse.
i need to know how can we do this from the scratch. Also is there anything optional available for mocking framework.
Any pointers or samples would be highly appreciated.
Thank you again.
A C# unit test shall not touch the database, you should mock the database. It should be possible to execute many thousands of unit test on your local machine (without external (internet, databases, other application)) within seconds (and you want to run them when you build your code).
That leaves us kind of with your question unanswered: what should your database layer tests do? It depends on what kind of logic you have in that assembly! If you have "business or decision" logic should should test that, if you have mapping logic test that. If all your database layer does if using (whatever db framework) to put the load on you database then you might not have anything worth testing there.
If you want to test logic performed by your database (say SP's) you should do that in the database project, and most likely not using mstest.
Of course you can use mstest to setup and tear down database and perform test, but those test will not be unit tests.

Junit - Test Hibernate Service Results

I have a DAO service which retrieves and saves data to Hibernate.
Could anybody point me to testing Methodology using JUnit for such service.
What is the best practice? When should I have passed test failed test and should I test exception?
You should test every possible path in your DAO. You would definitely use an in-memory database for your tests, such as HSQLDB.
One strategy would be to give the database some initial data in your setUp() method and clean it up on tearDown(), so all tests have a consistent working environment.
With these setup you can basically do everything... For example, if you want to test a save() method in your DAO, just add the new element and make sure that your table now has one more element. Moreover, fetch that element and compare it to the one you've inserted, it should obviously be the same.
Remember that you should always test every possible path.
I would also look into using DBUnit to ensure that your database is consistent and test independent. They have articles on how to get started and a tutorial. There a quite a few articles on IBM's DeveloperWorks blog as well that you might want to read.
I think using an in-memory database is often a good idea - for unit test. But the ideal is to combine fast unit tests with such a database with integration tests hitting the real database. There are subtle differences between, e.g., Hypersonic SQL and most production servers.
Consider using mocks for testing your error handling (i.e. mock the Hibernate session object and make it throw exceptions for certain operations)

Cleaning up data within SQLCompact DB between MsUnit tests

I'm playing with MVC2, Entity Framework and CTP4 using code only persistence. I've created some unit tests in MSUnit for my domain objects, including some to see how persistence works in this paradigm. I'm using Sql Server CE 4.0 for these tests. This works fine, except for one problem...data seems to be persisted between tests within the same class.
I have previous experience using Java, Hibernate Annotations, and HSQLDB and in that case the DB is created and torn-down on each test execution. In SqlCompact, however, I have a couple tests that use the same test data fixture and end up with constraint violations if I run them both.
I can fix this via some hacks to drop tables/delete data explicitly within [TestCleanup] but what is the proper way to ensure that I start with a fresh DB for each test when using SQL Compact in this case? I'm sure the answer is simple, but I can't seem to find it anywhere. Thanks.
EDIT: For the moment, I'm doing this, which works--but I don't like it. Better ideas are welcome:
[TestCleanup]
public void teardown()
{
mgr.Database.DeleteIfExists();
mgr.Database.Create();
}
I think a better approach is to add the code you have in teardown to [TestInitialize], which gets called before each test executes. Compare this with [ClassInitialize] which gets called once for the entire fixture.
I am more familiar with NUnit, and found this table helpful to map NUnit attributes to MSUnit
http://blogs.msdn.com/b/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx

Using PDO Sqlite in-memory Db for PHPUnit tests

I recently got PHPUnit working with xDebug for testing my Zend Framework applications. The fact I use ZF shouldn't make any difference to this question- just mentioned it for completeness.
Anyway, it all works fine, but now I want to set up an in-memory database using PDO SQLite. I have done this successfully and have created tables and inserted data. However this task seemed to take ages, the syntax from my Export did not match SQLites needs so I had to play around for a while.
Also SQLite does not support constraints (is that right?) which my application does use, so the whole process seems a waste of time if I cannot test my constraints.
Is using SQLite the right solution to my problem? Does anyone have any better ways of using it or any other DB solution to unit testing?
The idea of unit tests is to test smaller parts, so one way could be to work with small amounts of (static) sample data, for example as described in http://www.phpunit.de/manual/3.4/en/database.html
If you really need to test against a full database with all it's constraints, I think there is no way around just using the specific database of your application, for example MySQL.

unit testing with symfony + doctrine + PHPUnit

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