1

Here is something I was thinking about and I am wondering if anyone is doing this or if there are any resources online I can read for more information.

This is a brand new project I am working on. I am current doing unit testing and I have started writing browser UI tests. However there are a lot of problems that come up when you start UI testing (browser versions, javascript errors, ajax calls taking too long to run). I understand UI testing is important but right now I've just written a considerable amount of backend code and I want to test the entire process minus the browser portion.

I was thinking I could write a test that

  1. Inserts records into the DB
  2. Calls the controller action with test data just as the browser would
  3. Runs through the code from start to finish
  4. Assert that the correct info was written to/updated the DB
  5. Rollback the database changes

Is this something that is typically done? If so are there any sites that could help me get started on setting up these types of tests?

Thanks!

tereško
  • 58,060
  • 25
  • 98
  • 150
Rochelle C
  • 928
  • 3
  • 10
  • 22

2 Answers2

0

use in-memory database that mirrors your schema. Database connection should be injected to whatever is accessing the DB.

In-memory DBMS's for unit testing

Community
  • 1
  • 1
BlackICE
  • 8,816
  • 3
  • 53
  • 91
0

Backend: it's convenient to separate frontend tests from http server test. if you can manually create a http request then do it and test your server side logic (this technique is perfect when you do rest + js UI). as BlackICE said it's most convenient to use in-memory db. but it's sometimes not enough when it comes to compatibility. sometimes you just have to test on normal db. then try to do each test in separate transaction - then all you have to do is just rollback. you can also clear whole db and set it up before each test but that is time consuming. consider separating read only test from RW ones. for read-only you can set up db only once and save a lot of time

GUI: later test js and (if you need) html. you can't do this part without a browser - or to be more precise: without a js / html engine. html browsers are available in almost every commercial language (in java we have htmlUnit) but their compatibility and js support often is not good. therefore they are can be used only for very simple pages. you should also give a try to phantomjs. it's a headless js engine. currently we are using it in our frontend js test (rest + angular js) and we had no problems. it can be installed on server, without X environment.

but if you are doing pixel-precision application then i don't think you can do tests without using real browsers and selenium or sth like that

piotrek
  • 13,982
  • 13
  • 79
  • 165