mardi 1 août 2017

SpringBoot's DataJpaTest with Flyway

I'm using flyway in my project to setup the DB schema. When I try using the @DataJpaTest annotation to test some JPA layer I get this error upon startup:

> Caused by:
> org.flywaydb.core.internal.command.DbMigrate$FlywayMigrateSqlException:
> Migration V1__init.sql failed
> ----------------------------- SQL State  : 42581 Error Code : -5581 Message    : unexpected token: AUTO_INCREMENT : line: 2 Location   :
> db/migration/V1__init.sql
> ..../target/classes/db/migration/V1__init.sql) Line       : 1
> Statement  : CREATE TABLE mytable (    id INT NOT NULL AUTO_INCREMENT
> PRIMARY KEY,

It looks like it is trying to use HSQL instead of the regular SQL

Is there a way I can use @DataJpaTest with flyway ?

Modified require function doesn't use current file's path when imported

I'm using the proxyquire library, which mocks packages on import.

I'm creating my own proxyquire function, which stubs a variety of packages I use regularly and want to stub regularly (meteor packages, which have a special import syntax):

// myProxyquire.js
import proxyquire from 'proxyquire';

const importedStubs = {
  'meteor/meteor': { Meteor: { defer: () => {} } },
};

const myProxyquire = filePath => proxyquire(filePath, importedStubs);

export default myProxyquire;

Now I want to write a test of a file which uses one of these packages:

// src/myFunc.js
import { Meteor } from 'meteor/meteor'; // This import should be stubbed

export const myFunc = () => {
  Meteor.defer(() => console.log('hi')); // This call should be stubbed
  return 'test';
};

And finally I test it like this:

// src/myFunc.test.js
import myProxyquire from '../myProxyquire';

const { myFunc } = myProxyquire('./myFunc'); // error: ENOENT: no such file

describe('myFunc', () => {
  it("should return 'test'", () => {
    expect(myFunc()).to.equal('test');
  });
});

Note that my last 2 files are nested inside a subfolder src. So when I try to run this test, I get an error saying that the module ./myFunc couldn't be found, as it is being looked for in the "root" directory, where the myProxyquire.js file is, not the src directory as expected.

How to access soap response dynamically from HP UFT using custom code

I am pretty new to HP UFT and C#.

I am testing soap services. I want to dynamically parse my response xml and do some validations on it.

But to start with, I do not know how to get my response xml in to a string/xml file. I have tried and failed

Can anyone help me with this please?

Rspec rails api controller index test

I'm trying to test an api controller action with rspec, but since i am quite new to rspec i can't make it work. I have the following index action: render json: @website.jobs

I have to find all associated jobs to a website by name. Here is my spec:

let(:endpoint) { FactoryGirl.create(:website) }
let(:job) { FactoryGirl.create(:job) }

subject do
  get :index, params: { format: :json, 
                       name: endpoint.name }
end

expect(subject.body).to include(:job)

Am i doing something wrong, or am i missing something ?

Test spark failover

In my project I perform some side effects inside RDD's actions and transformations. I want to test that my business logic works even if Spark engine had to retry computations for some partitions. So I'm trying to simulate failures during the computation.

object Test extends App {
  val conf = new SparkConf()
  conf.setMaster("local[4]")
  conf.setAppName(getClass.getName)
  val sc = new SparkContext(conf)
  try {
    val data = sc.parallelize(1 to 10)
    val res = data.map(n => {
      if (TaskContext.get().attemptNumber() == 0 && n==5) {
        sys.error("boom!")
      }
      n * 2
    }).collect()
  }
  finally {
    sc.stop()
  }
}

But it doesn't work: exception is propagated to a driver. Seems that the Spark tries to failover only its internal errors. Is there any way to test it?

Device Farm Parsing Error

I am trying to send to the AWS Device Farm a test Suite with 2 Test classes and I'm receiving this Parsing Error message.

This is my testng.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://ift.tt/19x2mI9">
<suite name="Default Suite">
    <test name="test">
        <classes>
            <class name="TestClass"/>
            <class name="TestSingleUrl"/>
        </classes>
    </test>
</suite>

And this is the error message I'm getting:

Failed to generate the test suites Data Provider Annotation Method Found: public java.util.Iterator TestClass.createData() throws java.io.IOException [TestNG] [ERROR] Cannot instantiate class TestClass

I ran the test in my local device, and it is working well.. I just change the driver to a RemoteWebDriver when I send to Device Farm

How to test called promises not returned in tested function

first of all, I've been trying almost everything to make this code work, and I achieved, the problem is that I don't like the approach, and I wanted to know if there was something better I could do in order to make the TEST code more readable, but functional.

The main problem here is that "I can't modify the functionToTest" and I have to write tests that would be basically checking that the API calls are being done.

How with the given code would you run the assertions after functionToTest has finished?

PS: The code is shit, I know, but sometimes you just have to deal with it, you can't do more thank just test the shit out of it before refactoring it :(

const firstApiCall = () => {
    return new Promise(function(resolve,reject) {
        setTimeout(() => {
            resolve('firstApiCall success');
        }, 3);
    });
};

const secondApiCall = () => {
    return new Promise(function(resolve,reject) {
        setTimeout(() => {
            resolve('secondApiCall success');
        }, 3);
    });
};

const functionToTest = () => {
    setTimeout(() => {
        firstApiCall().then(result => {
                setTimeout(() => {
                    secondApiCall()
                }, 2)
            })
    }, 15)
};

Basically the code that generates the mocks does something like this, so at the end you have synchronous code

const firstApiCall = () => {
    return {
        then: (cb) => {
            cb('firstApiCall success')
        }
    }
};