Design pattern for exposing static functions in C/C++ only to unit tests [on hold]

I have some static free functions (the don’t belong to a class) in a C++ file. I want them to still be only visible within such module and to be free, but I want to test them with unit tests as well.

As far as I can see, the are several possible options:

  • Using macros, enable/disable the static keyword depending on whether or not a variable (TEST_MODE) is defined or not:
#ifdef TEST_MODE    #define static #endif 
  • Use ‘private headers’: create a header file whose name ends with _private and whose location is in include/private.

  • Declare the functions in the normal header file adding like a private section with code comments. Like /////// PRIVATE SECTION ///////

  • Include the *.cpp file in which they are declared (personally I don’t like this option at all)

  • Group the private functions in a ‘private’ namespace. Like namespace myNamespace { namespace private { .... } }. The problem with this one is that it can’t be used in plain C.

  • Use compiler directives for hiding stuff, like __attribute__(("hidden"))

I would say that my favourite one is the private header, it seems to be clean and does not need namespaces, in case the language doesn’t support them.

Which one is considered the best practice?

Trouble spying on service call Angular 8 Unit Test

I am trying to implement a test and I can’t seem to figure out what is wrong..

I have a method like so..

sendData() {    if (!this.dataSent) {       this._subscription.sendData(data).subscribe(() => {});    } } 

Now I have an element on my page a button like so

<button id="data-btn" (click)="sendData()">     SEND DATA </button> 

now in my spec.ts I am doing this

describe(...     let subscriptionService: SubscriptionService;     //...      beforeEach(async(() => {         const subscriptionServiceSpy: SubscriptionService = jasmine.createSpyObj(            'SubscriptionService', ['sendData', 'anotherMethod']         );          TestBed.configureTestingModule({             //...             providers: [                 { prodive: SubscriptionService, useValue: subscriptionServiceSpy }             ]         }).compileComponents();     }));      beforeEach(() => {        subscriptionService = TestBed.get(SubscriptionService);     });      it('should send data if element has been clicked', () => {         const el = fixture.debugElement.query(By.css('#data-btn'));          click(el); // helper method that clicks an element          expect(SubscriptionService.sendData).toHaveBeenCalled();     })  }) 

now technically this does pass.. but in the console I am getting this error

ERROR TypeError: Cannot read property 'subscribe' of undefined     at Component.sendData 

Am I doing something wrong??

Wounds – one unit or several?

Having played my first session of Monster of the Week two weeks ago, one thing about the rules confused me. When you receive harm in the game, it should go like this:

When you take harm, the Keeper will tell you what happened and how many points of harm it was. Mark off that number of boxes on your harm track. (pg. 110)

This leads me to believe that wounds is just a collected amount. However, in the Healing portion on the very next page the wording leads me to believe that a wound is several units 6 boxes marked (1×2-harm wound and 1×4-harm wound), being a moderate wound and a serious wound.

Which of the interpretations would you say is the correct one, or which do you prefer and why?

Kindly, Mildly/seriously wounded Hunter

Why is the Nginx PHP Unit ignoring the root parameter in this configuration file?

I’m trying to move mywebsite.com from a multisite WordPress installation into its separate WordPress installation folder. I’ve already setup a separate database and created a new file wp-config.php for the new WordPress installation with the information needed for the new installation. The problem is that when I switch the root parameter in the Nginx configuration file for the old multisite installation folder to the new one, the old website is still loaded by Nginx.

/etc/nginx/sites-available/mywebsite.com.conf

server {     listen      80;     listen      [::]:80;     server_name mywebsite.com;     root        /var/www/wordpress_mywebsite/; # <-- this was changed to point to                                                #     the new single site installation                                                #     the old multisite installation                                                #     folder is /var/www/wordpress      if ($  scheme = "http") {         rewrite ^ https://$  server_name$  request_uri? permanent;     }      location / {         try_files $  uri @index_php;     }      location @index_php {         proxy_pass       http://127.0.0.1:8090;         proxy_set_header Host $  host;     }      location /wp-admin {         index index.php;     }      location ~* .php$   {         try_files        $  uri =404;         proxy_pass       http://127.0.0.1:8091;         proxy_set_header Host $  host;     }      listen 443 ssl; # managed by Certbot     listen [::]:443 ssl; #ipv6only=on; # managed by Certbot     ssl_certificate /etc/letsencrypt/live/mywebsite.com/chained.pem; # managed by Certbot     ssl_certificate_key /etc/letsencrypt/live/mywebsite.com/domain.key; # managed by Certbot     include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot     ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot      ssl_client_certificate /etc/nginx/certs/cloudflare.crt;     ssl_verify_client on; } 

Is this unit test or integration test?

This is a piece of test code made for the Angular application.

The router object is a mock provided by the RouterTestingModule dependency. I wonder if such a test can be considered a unit test (because it actually tests only one element and the fact that it calls some method – without checking its result), or should it be called an integration test (due to the fact that it still call external dependence)?

it('should trigger the navigation to `/home`', async(() => {   const link = fixture.debugElement.nativeElement.querySelector('.home-link');    link.click();    expect(router.navigateByUrl).toHaveBeenCalled(); }))

Stripe Component Unit Testing

I am trying to do unit testing on Stipe’s React CardElement component, but I cannot find how to pass data into the component and people who use unit test methods that type the values in seem to have them wiped away. This unit test would be important to testing my React page, anyone know how this can be achieved?

Useful Link:

CardElement Component

Unit Tests vs System Tests

I’ve always know Unit Tests to be something you do in code. You write functions to test other functions. Our team has been working with the same project manager for a while now and he’s always referring to system tests as unit tests. By system tests I mean the kinds of tests where a user follows a test plan and performs actions on an application to ensure it meets the requirements. This PM is an Indian offshore resource.

Is this use of terminology something unique to this person? Is it an Indian thing (like “do the needful”)? Or am I just not aware that there’s more than one definition for what a unit test is?

Class ‘Magento\TestFramework\TestCase\AbstractController’ not found when running unit test for custom module

I tried to make a unit test for my custom module like this:

app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php

namespace MyCompany\UnitTest\Controller;  class SpinTest extends \Magento\TestFramework\TestCase\AbstractController {     public function testLogin()     {         $  params = [           'customer_id' => '3'         ];         $  this->getRequest()->setPostValue($  params);         $  this->dispatch('spin/run');         $  result = $  this->getResponse()->getBody();         $  this->assertEquals('200', $  result['status']);     } } 

and ran the unit from terminal:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist app/code/MyCompany/UnitTest/Test/Unit/Controller/ 

but i got an error like this:

Class ‘Magento\TestFramework\TestCase\AbstractController’ not found in /var/www/mage2/app/code/MyCompany/UnitTest/Test/Unit/Controller/SpinTest.php on line 4