0

I'm using the library openldap for c++ to implement some authenticattion and queries for an ldap DB. I want to write unit tests for my code.

My question is, is it done like with sql DBs? for instance with sql, in each unit test you do something like that: drop the test DB, create a new one, add some users, assert your apis.... etc.

All in all I want to know the convention for writing ldap-db unit tests.

mkmostafa
  • 3,071
  • 2
  • 18
  • 47

1 Answers1

0

If you're talking about unit tests then you should mock your LDAP API and test only your code, not the LDAP API implementation. You can use Google Mock for your mocks.

But I think you're referring to integration tests, for that same strategy as with database integration tests apply. You setup the environment - bring up the server, populate the entries, assert that the code works against it and then tear down that environment.

In Java I would use in-memory LDAP server for integration tests, you could try and find one that you can embed and run only from memory in C/C++.

See What's the difference between unit, functional, acceptance, and integration tests?.

Zoran Regvart
  • 4,630
  • 22
  • 35
  • I know the difference between integration and unit tests. I am talking about unit tests. for example a unit test for a function that validates a user and adds them to the LDAP DB. What I need is how to mock the LDAP DB as you have mentioned. – mkmostafa Nov 12 '15 at 09:09