Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 142501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:56:48+00:00 2026-05-11T07:56:48+00:00

So, I’m trying to stub a database connector in order to write tests for

  • 0

So, I’m trying to stub a database connector in order to write tests for it. The problem is that the database connector is a pretty thin layer, and the queries to it are somewhat open-ended. I want my code to be able to ask for a variable from the database, and the connector should be OK with this. The signature for this call looks something like this:

dim = getDimension(self,dimensionName,otherIndentifyingInformation) 

(This is all in MATLAB – hopefully the answer is language-agnostic, or at least not infeasible in MATLAB.)

When I use it in my code, dimensionName is one of a few things that are stored in the database. If the code calls it, and it doesn’t exist, that’s fine. The problem here is that I want to test some code that makes two calls to getDimension, something like:

alt = conn.getDimension('alt',otherID); str = conn.getDimension('str',otherID); 

For (hopefully) obvious reasons, alt and str are not guaranteed to be the same. In fact, they’re typically not.

So, my question. If I want to stub getDimension to return good test values, how can I do this? Creating getDimensionAlt seems kludgy, since the number of things that could come out of the database is somewhat unbounded, and that would be a pain to maintain. Is there a better way than putting logic in my stub objects? That just seems like the wrong way to go about this…

EDIT: Setting up a testDB was suggested. Wouldn’t I have to set up a testDB for each test case, then? And in each test, I’d have to create a DB connection, return it as a stub, run the test, and then clean up the DB connection. This seems like it would be a lot of overhead for each test, especially when it isn’t even the system I’m testing.

I suppose it’s possible to set up a testDB, and fill it with the appropriate values each time. Is that good practice?

EDIT 2: Perhaps my question is unclear. I have a small piece of code I’m trying to test. It’s not a lot more complicated than those two lines above, and I’d like to test it cleanly. The problem is that stubbing the getDimension call is dependent on the arguments. I don’t need to reuse this stub with other tests.

I think the answer might be ‘It’s OK to have simple logic in your stubs.’ This is all confounded by the fact that there’s no anonymous classes or stubbing framework in MATLAB, so that’s hard, but I want to make sure what I’m doing is conceptually clear before I go off and write a stubbing framework in MATLAB.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:56:49+00:00Added an answer on May 11, 2026 at 7:56 am

    I think setting up a testdb is a good idea if you’re doing automated integration tests or acceptance tests. This usually calls for tests where you test the whole stack (UI, application, database, services etc.) at once.

    Unit testing is quite different, they are used during development and not during testing, therefore they should be quicker to run, quicker to change and quicker to write. Its usually a good idea to have unit tests only depend on the small piece of code they’re testing. This makes them less brittle, easier to understand and makes developers more willing to run them often.

    Using stubs in unit tests is a good idea. The problem you seem to run in to is that if you want to reuse stubs for many tests their behaviour can get very complex, in the worst case you’re rebuilding the thing they are supposed to stand in for. This can also happen if you are testing too much at one time.

    The solution to this is to have more smaller stubs that only implement the behaviour for one or a few tests and have your tests only test a single behaviour. Tests that test lots of behaviour at once are useful too but they’re not unit tests, you should move them to your integration test suite (and can run on a real database). I’m not sure about matlab but in many languages you have mocking frameworks you can use to handle creating stubs and setting up behaviour for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll want to take advantage of the fact that union… May 12, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer "This method returns the current location of a UITouch object… May 12, 2026 at 1:15 am
  • Editorial Team
    Editorial Team added an answer I had some issues with sqlalchemy's performance as well -… May 12, 2026 at 1:15 am

Related Questions

So, I've read that it is not a good idea to install VS2008 on
So I am writing a registration form and I need the display name to
So, I know that try/catch does add some overhead and therefore isn't a good
So, I am seeing a curious problem. If I have a function // counter
So, I am a total beginner in any kind of Windows related programming. I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.