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 6864495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:55:08+00:00 2026-05-27T02:55:08+00:00

I have a C module and I want to refactor a little bit. There

  • 0

I have a C module and I want to refactor a little bit. There are some global variables and structures which are not hidden (in the module.h file). I use this variables in some test case but nowhere else so I thought it’s a good idea to set them to static. In my test cases I extern these variables and fill with test values. But if they will be static variables I can’t reach them from the test case. I don’t want to write getter and setter methods and put it to the .h file, because I want to hide this variables.

I know if I include the .c file into my test case I can see the static variables.
Is there any other way to fill these variables?

I use cygwin and gcc, the test framework is CppUtest.

Thanks in advance.

  • 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. Editorial Team
    Editorial Team
    2026-05-27T02:55:08+00:00Added an answer on May 27, 2026 at 2:55 am

    There are two main possibilities:

    1. The difficulty of testing is showing that the interface provided by the module is incomplete.
    2. Your unit testing is prying into the internals of the module in a way that consumers would never need to do.

    If the problem is an incomplete interface, then you can add the extra interfaces that make the module more easily testable, and more generally usable. For example, if the static variables are counters of some sort, you might need to add a ‘reset’ method to set the counters back to zero, ready for the next part of the unit testing, or (in the more general use case) to allow the statistics to be zeroed so that you can accumulate the statistics afresh.

    If the problem is unit testing needing to probe more deeply than consumers need to probe, then I don’t see anything wrong with the test code using #include "sourcecode.c". It keeps the module code clean for general use; it allows the unit test to probe more deeply than it would otherwise. It converts the test code from ‘black box’ testing to a form of ‘white box’ testing – the test can see more of the tested code than a regular black box test can. But that’s sometimes helpful. It is often an intermediate stage during development. Once you have all the black box testing in place, you may not need to be concerned with probing the internals in the same way – until you make changes.

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

Sidebar

Related Questions

I have a file that I want to read in using the File::Slurp module
I want to run some Python unit tests from my Maven module. I have
i have written module which reads and write on /proc file and is working
I have a bunch of scripts which I want to refactor into modules. This
Hello all I have some very important system files which I want to protect
I have an admin module and I want it to serve dynamic controllers, i.e.
I have created a simple Python module and want to distribute it with pip.
I'm writing a module and want to have a unified exception hierarchy for the
I have a PowerShell module called Test.psm1. I want to set a value on
I have a class that I want to include in a GWT module. Unfortunately,

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.