Questions tagged [unit-test]

27 questions
44
votes
5 answers

Unit testing of stored procedures

I've been considering this for quite a long time now. The basic question is: how to unit test stored procedures? I see that I can set up unit tests relatively easily for functions in the classic sense (I mean they get zero or more arguments and…
András Váczi
  • 31,778
  • 13
  • 102
  • 151
11
votes
4 answers

Temporary schema per connection?

I am trying to migrate my unit tests from H2 to Postgresql. Currently, H2 gives me an in-memory schema such that each connection maps to a unique schema, creates the tables, runs the test, and drops the schema. The schema creation and destruction is…
Gili
  • 1,049
  • 1
  • 16
  • 31
11
votes
2 answers

How can I fake inet_client_addr() for unit tests in PostgreSQL?

I have a simple stored procedure whose return value depends on the value of inet_client_addr(). How can I override inet_client_addr() for the purpose of unit tests when testing my stored procedure? The only solution I've come up with so far is to…
Flimzy
  • 609
  • 1
  • 5
  • 18
7
votes
1 answer

Test Driven Design for postgres procedures

I am looking to introduce a test driven design style to writing my stored procedures for a postgresql database implementation. I have seen that pgTap is a popular unit testing tool for postgres and correctly allows for the tests to be written in SQL…
Russell Ormes
  • 193
  • 1
  • 9
6
votes
3 answers

EXPORT specific columns to INSERT statements

Is there a way to export specific columns and a fixed number of rows from a table to INSERT statements? I am trying to generate these for unit testing based on a large production table so using something like "Generate Scripts" in SQL Server…
Robin
  • 333
  • 2
  • 4
  • 8
5
votes
3 answers

Can PostgreSQL support integration test with some kind of throwaway overlay?

It's a common problem to write integration tests that include a database. If the test changes the database then it could effect other tests or the next run of itself. I know that I could wrap my test in a transaction and rollback the transaction…
Thomas Koch
  • 151
  • 2
5
votes
1 answer

Reinitialize Table Values in SQL SSDT Unit Testing

I am creating SQL Server Unit Tests. We are testing various stored procedures. In Unit testing principles, it is good practice to setup a small database table, populate values, and tear down (truncate/delete) the database tables, and resetup for…
user162241
5
votes
1 answer

Optimizing MySQL 5.6 for unit tests

We have a MySQL instance for unit tests. Our unit tests work very heavily on MySQL. Therefore, we put /var/lib/mysql dir in tmpfs file system because we don't need persistent data in unit tests. Our performance peaked when we did this; however, I…
confiq
  • 153
  • 8
5
votes
2 answers

DROP DATABASE statement cannot be used inside a user transaction

Not really sure if this question belongs here, but I hope someone could help me out. I've made integration tests going all the way down to the database (using mssql localDB). I want each test to run independently with it's own data - I want to…
S. Peter
  • 185
  • 2
  • 5
4
votes
1 answer

What is the standard de facto unit test framework for Postgres?

I am new to Postgres and as I am about to start writing more and more code with it (script with procedures, etc.) I am wondering what is the "standard de facto" (more used, bigger community, open source, etc) unit test framework for it. Googling I…
Randomize
  • 1,203
  • 2
  • 21
  • 36
3
votes
1 answer

What does @RC mean in SSDT SQL Server Unit Testing?

In Sql Server Unit Testing, SSDT, what does @RC stand for? Does it mean Row Count, or Row Column? Team wants to understand, we have been using it for long time, good tool which works, just curious.
user173948
3
votes
1 answer

Sql Server Stored Procs vs Linq with C# and unit testing

I'm going to run into a situation where I am, where the stored proc vs Linq is going to come up. I know I'm asking this in the DBA stackexchange so most of you might say use stored procs, but I'm curious on the unit test suites that exist in SQL…
user441521
  • 133
  • 3
2
votes
3 answers

How do I unit test queries which are based on dates from now?

I've had a hard time making unit test for most of my queries because they are tied very closely to current dates and data which is added to the database could modify the result of the unit test. For the most part I've been able to avoid problems by…
Mallow
  • 123
  • 1
  • 5
2
votes
2 answers

Are SQL unit tests supposed to be so long?

I am writing stored procedures with some non-trivial business logic. I am trying to unit test them, but the actual tests end up being quite long (shorter ones starting at 40-50 LoCs, using commonly 4 different tables), which doesn't seem very…
IvanLoginov
  • 103
  • 1
  • 7
2
votes
1 answer

Write a slow SQLITE query to test timeout

Is it possible to write a 'simple' SQLite query that will take more than 5 seconds to run. I am writing some unit-tests in my application to log slow queries, to that end, I would like a slow query that I know will take more than 5 or 10 seconds to…
Simon Goodman
  • 145
  • 1
  • 7
1
2