jeudi 1 août 2019

Testing a function that has some code dependent on a service that's unavailable during local testing?

I'm using pytest to test a Flask API that also makes use of MQTT. I'm late to the TDD game so this question could well be answered elsewhere but I can't think of the right way to frame it, so can't find anything that seems to answer it for me. This question that deals with mocking during integration tests sounds like it's on the right track.

Basically one of my tests looks like this

response = testing_client.post(
         "/api/users/1/devices",
         data=json.dumps(dict(device)),
         headers={"Authorization": "Token %s" % auth_token},
         content_type="application/json",
     )
assert response.status_code == 200

The problem is that the corresponding bit of code that handles these POST requests also publishes an MQTT message when the request has been handled i.e.

publish.single(f"{device_id}/active", msg, hostname=os.environ.get("MQTT_BROKER_URL"), retain=True, qos=0, port=int(os.environ.get("MQTT_BROKER_PORT")))

The API and MQTT broker are separate containers managed using Docker compose. When I'm testing locally there is no MQTT broker running and so any test here fails (even though I don't actually care about testing the MQTT code).

For any calls to the DB (Postgres) I actually set up a specific postgres container for testing and run tests against this. Should I do the same thing for MQTT testing (I would then also have to do it during the CI pipeline on GitLab), or is there a much more obvious solution that I am missing?

How to test the following async function in angular?

code to test:

async showSuccess() {
  this.msgs.push({severity: 'success', summary: 'Success.'});
  await delay(1000);
  this.msgs = [];
}

here's the test I tried but await delay(1000) isn't covered and so isn't this.msgs = []

it('should show message', async() => {
        spyOn(component, 'showSuccess');
        component.showSuccess();
        expect(component.showSuccess).toHaveBeenCalled();
    });

The method signature line is covered and the msgs being pushed is covered but not the last two lines.

What are regexes for variables in adf 12c?

Im trying to learn how to make loadtest for login on webservice based on adf 12c. But Ive got really big trouble with looking for a current regexes. Of course i found lots of them but only afrWindowId is actual.

I was trying with this tutorial but regex don`t find parse.https://www.redline13.com/blog/2018/01/oracle-adf-load-test/

How to stubb a private method call of my tested class

I am actually trying to Test a method, that needs a DB Connection (i cant make it at this moment), so i want to test the method ignoring the DB Connection.

@Test
public void Test(){
         ExampleClass ex = new ExampleClass();

         ex.methodA();
}

My method is calling an inner class, and that class is calling the private method that broke my test. I cant actually call the private method of the Tested class, because is not visible.

public class ExampleClass{

      public methodA(){
                    .......
                    return new innerClass();
      }

      private innerClas(){
            public methodB(){
                             ..........
                              ..........
                              Object a = send(....); //This is my DB Connections that crashes.
            }

      private send(....){
                       .......... 
                         .........
      }
}

I need to ignore the Send method of the Tested class, because there is the DB Connection. If i can stub that send, of ignore it will be enough.

JEST does not trigger mock functions Vue js

I have a simple component with unit test like below. I am trying to trigger click event on anchor but I think it does not happen because of error:

Expected mock function to have been called, but it was not called.

Component:

<template>
<a @click="fetchAll" class="icon">
            <Icon class="icon"  scale="2" />
        </a>
</template>
<script>
export default {
   methods: {
       fetchAll() {}
   }
}
</script>

Test:

it('should fetch all', () => {
        const wrapper = shallowMount(Component, {
            stubs: [ 'Icon'],
            localVue
        })

        const fetchAll = jest.fn()
        wrapper.setMethods({ fetchAll })
        wrapper.find('.icon').trigger('click')
        expect(fetchAll).toBeCalled()
    })


What is wrong?

Quarantine mode for the fixture or test

Is it possible to run some tests in quarantine mode and run others without the mode? For example, we have some lightweight tests and we don't need 3 tries for them, but for others it can be necessary

Use copied text in Testcafe Naviagation to change URL

I select some text with

t.selectText(Selector('#neededURL'), 0, 60) [can copy it if needed]

and want to use this text in navigateTo function, how can i do this?