vendredi 30 septembre 2016

Test suite recommendation

is there a cloud based test suite tool that you recommend for mobile? my ideal scenario would be the user can launch a popup in the mobile app during UAT - so im assuming this test suite would have a mobile app API - and that feedback when submitted is logged so we (developers) can then see it in browser and assign it to a test case, etc.

Any suggestions/recommendations would be really appreciated.

Tool to Automatically Wrap C# classes? [on hold]

Say I have:

public class SelectedEvent
{
    private bool m_isSelected;
    public ProxSafeEventType Event { get; set; }
    public string Text => Event.ToLocalizedString();

    public bool IsSelected
    {
        get
        {
            return m_isSelected;
        }
        set
        {
            if (m_isSelected != value)
            {
                m_isSelected = value;
                OnPropertyChanged(nameof(IsSelected));
            }
        }
    }

    public SelectedEvent(ProxSafeEventType evt, bool selected)
    {
        Event = evt;
        IsSelected = selected;
    }

    public event PropertyChangedEventHandler PropertyChanged;

    public void OnPropertyChanged(string name)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }
}

I am looking for something that can generate something like:

    public class SelectedEventWrap
    {
        private SelectedEvent _impl;
        public virtual ProxSafeEventType Event { get { return _impl.Event} set { _impl.Event = value; } }
        public virtual string Text => _impl.Text;

        public SelectedEventWrap(SelectedEvent impl)
        {
            _impl = impl;
        }

        public virtual bool IsSelected
        {
            get
            {
                return _impl.IsSelected;
            }
            set
            {
                _imple.IsSelected = value;
            }
        }

        public virtual SelectedEvent(ProxSafeEventType evt, bool selected)
        {
            _impl.SelectedEvent(evt, selected);
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string name)
        {
            _impl.OnPropertyChanged(name);
        }
}

The idea is, given a class, wrap all public members, methods, properties, etc and make everything virtual.

This makes the class very easy to mock.

Is there a tool that can generate this sort of thing?

Android + Integration test + PowerMock: How to test private methods, static methods and final classes?

I'm having some problems when I try to test methods and classes in Android. I know that to make Unit Tests I could use PowerMock to test private methods, static methods and final classes. But when I try to do the same with Integration Tests I don't know how to do it.

1) Is there any other way (library or wherever) to test those kind of scenarios?

2) Is there any way to use PowerMock in both tests (Unit and Integration)? Because I'm having some dependencies problems.

Thank you!

Failed to load .html in Angular 2.0.0 testing

I have a problem with TestBed in Angular 2.0.0

    beforeEach( async(() => {
        TestBed.configureTestingModule({
            declarations: [
                SomethingComponent
            ]
        }).compileComponents(); // compile template
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(SomethingComponent);
        comp = fixture.componentInstance;
    });

    it('test', async(() => {
        fixture.detectChanges();
        expect(true)
    }));

Given the component:

@Component({
    templateUrl: 'app/components/something/something.component.html'
})

I get the error:

Firefox 48.0.0 (Mac OS X 10.11.0)
Failed: Uncaught (in promise): Failed to load app/components/something/something.component.html
resolvePromise@node_modules/http://ift.tt/2dweKa9
resolvePromise@node_modules/http://ift.tt/2cGd3AR
scheduleResolveOrReject/<@node_modules/http://ift.tt/2dwf3Cb
ZoneDelegate.prototype.invokeTask@node_modules/http://ift.tt/2cGePC3
ProxyZoneSpec.prototype.onInvokeTask@node_modules/http://ift.tt/2dwePL6
ZoneDelegate.prototype.invokeTask@node_modules/http://ift.tt/2cGexey
Zone.prototype.runTask@node_modules/http://ift.tt/2dwfeNG
drainMicroTaskQueue@node_modules/http://ift.tt/2cGeiA7
ZoneTask/this.invoke@node_modules/http://ift.tt/2dwfUCy

I think it might be because the configuration isnt set up right. I am using gulp to precompile TypeScript into JavaScript, and I have the following project structure:

|_ grails-app
|_ frontend
  |_ angular
    |_ app
    |    |_ components
    |    |     |_ something
    |    |          |_ something.component.ts
    |    |          |_ something.component.html
    |    |_ model
    |    |_ test
    |    |_ app.module.ts
    |    |_ app.routing.ts
    |    |_ main.ts
    |_ assets
    |_ build
    |    |_ app
    |        |_ components
    |        |      |_ something
    |        |          |_ something.component.html
    |        |          |_ something.component.js
    |        |          |_ something.component.js.map
    |        |_      
    |        |_      
    |        |      
    |_ node_modules
    |_ gulpfile.js
    |_ karma.conf.js
    |_ karma-test-shim.js
    |_ systemjs.config
    |_
    |_
    |

But if I assume that the html file is precompiled, and remove the command '.compileComponents()' from the test, I get the following error:

Firefox 48.0.0 (Mac OS X 10.11.0)
Error: Cannot create the component SomethingComponent as it was not imported into the testing module! 

And if I remove the 'async', I get this error:

Firefox 48.0.0 (Mac OS X 10.11.0)
Error: This test module uses the component SomethingComponent which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test. 

In karma-test-shim.js, I have:

System.config({
baseURL: '/base/',
paths: {
    // paths serve as alias
    'npm:': 'node_modules/'
},
map: {
    'app': '/base/build/app/',
    '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
    '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
    '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
    '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
    '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
    '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
    '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
    '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

    // angular testing umd bundles
    '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
    '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
    '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
    '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
    '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
    '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
    '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
    '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',

    // other libraries
    'rxjs': 'npm:rxjs'
},
packages: {
    'app': {
        defaultExtension: 'js'
    },
    'rxjs': {
        defaultExtension: 'js'
    }
}
});

I hope someone can help me figure out, what Im doing wrong in configuration.

NodeJS Express Application Testing - How to submit CSRF token when testing with Mocha and Chai?

I'm trying to write a test for a POST route in my Express application using Mocha, Chai and ChaiHttp, but I can't get it to work due to the fact that I keep getting an HTTP 403 response whenever submitting my CSRF token. Below is the code that I have up until now:

express.js configuration file

...
  app.use(session(config.SESSION));
  // csrf is the 'csurf' module
  app.use(csrf());

  app.use((req, res, next) => {
    res.cookie('XSRF-TOKEN', req.csrfToken());
    return next();
  });
...

User.test.js

'use strict';
process.env.NODE_ENV = 'test';

const User = require('../server/models/User');
const chai = require('chai');
const chaiHttp = require('chai-http');
const server = require('../index');
const utils = require('../utils');

chai.use(chaiHttp);

describe('Users', () => {
  beforeEach((done) => {
    User.remove({}, (err) => {
      done();
    });
  });

  after((done) => {
    server.close();
    done();
  });
...
 /*
   * [POST] /user
   */
  describe('[POST] /user', () => {
    it('should return a JSON object with a "success" property equal to "true" when creating a new user', (done) => {
      const userObj = utils.generateUserObject();

      chai.request(server)
          .get('/api')
          .end((error, response) => {

            userObj._csrf = utils.extractCsrfToken(response.headers['set-cookie']);


            /*
             * Accurately logs the _csrf property with the correct CSRF token that was retrieved via the initial GET request
             * 
             * Example output:
             * 
             * { 
             * username: 'Stacey89',
             * first_name: 'Gregg',
             * last_name: 'King',
             * ...
             * _csrf: 'vBhDfXUq-jE86hOHadDyjgpQOu-uE8FyUp_M' 
             * }
             *
             */ 


            console.log(userObj);

            chai.request(server)
                .post('/api/user')
                .set('content-type', 'application/x-www-form-urlencoded')
                .send(userObj)
                .end((err, res) => {
                  res.should.have.status(200);
                  res.body.should.be.a('object');
                  res.body.should.have.property('success').eql('true');
                  done();
                });
          });
    });
...

utils.js

...
  extractCsrfToken(cookiesObj) {
    const cookiesArray = Array.prototype.join.call(cookiesObj, '').split(';');
    let csrfToken = 'NOT FOUND';

    cookiesArray.forEach((cookie) => {
      if (cookie.includes('XSRF-TOKEN')) {
        csrfToken = cookie.split('=').splice(1, 1).join('');
      }
    });

    return csrfToken;
  }
...

When I run the above test, I get the following error:

ForbiddenError: invalid csrf token
...
POST /api/user 403

The strange thing is that if I do a POST request from Postman with the exact same configuration as the one previously described, I successfully get the response I am looking for and the form submission succeeds.

It appears to not be working only when submitting the userObj from my test suite.

Robot Framework - get span element from table

I'm trying to write some test cases to automatically test my websites but I'm having trouble clicking on checkbox witch is situated on every single row in the left column. User can click on every cell in the row he wants and checkbox will became checked or unchcked..

But I'm not able to simulate this click into table cell. First I'm trying to get some cell into variable and then to click on this cell using this variable like this:

    Page Should Contain Element     xpath=//div[contains(@id,'-tableCtrlCnt')]
    ${item1}    Get Table Cell  xpath=//div[contains(@id,'-tableCtrlCnt')]/table/tbody  1   2
    Click Element   ${item1}

But I'm getting error on the second line of code, I just cannot get the column.
The error/fail is:

Cell in table xpath=//div[contains(@id,'-tableCtrlCnt')]/table/tbody in row #2 and column #2 could not be found.

And this is how part of my html code looks like:

<div id="__table1-tableCtrlCnt" class="sapUiTableCtrlCnt" style="height: 160px;">
<table id="__table1-table" role="presentation" data-sap-ui-table-acc-covered="overlay,nodata" class="sapUiTableCtrl sapUiTableCtrlRowScroll sapUiTableCtrlScroll" style="min-width:648px">
<tbody>
<tr id="__table1-rows-row0" data-sap-ui="__table1-rows-row0" class="sapUiTableRowEven sapUiTableTr" data-sap-ui-rowindex="0" role="row" title="Click to select or press SHIFT and click to select a range" style="height: 32px;">
<td role="rowheader" aria-labelledby="__table1-ariarowheaderlabel" headers="__table1-colsel" aria-owns="__table1-rowsel0"></td>
<td id="__table1-rows-row0-col0" tabindex="-1" role="gridcell" headers="__table1_col0" aria-labelledby="__table1-0" style="text-align:left" class="sapUiTableTd sapUiTableTdFirst">
  <div class="sapUiTableCell">
  <span id="__text37-col0-row0" data-sap-ui="__text37-col0-row0" title="1010"   class="sapMText sapMTextMaxWidth sapMTextNoWrap sapUiSelectable" style="text-align:left">1010
  </span>
  </div>
</td>
<td id="__table1-rows-row0-col1" tabindex="-1" role="gridcell" headers="__table1_col1" aria-labelledby="__table1-1" style="text-align:left" class="sapUiTableTd">
  <div class="sapUiTableCell">
  <span id="__text38-col1-row0" data-sap-ui="__text38-col1-row0" title="Company Code 1010" class="sapMText sapMTextMaxWidth sapMTextNoWrap sapUiSelectable" style="text-align:left">Company Code 1010
  </span>
  </div>
</td>
</tr>
...
</tbody>
</table>
</div>

Don't you have any idea how to solve this click into table issue?

Can OWASP ZAP be performed on a protected website?

I am new to ZAP 2.5 and I have these questions that are yet answered as of the moment:

  1. Can ZAP be performed in a protected website? Note that I don't know what method is used to protect the website. But whenever I try to perform ZAP with it, it only checks the Log In form of the website; ZAP doesn't dig deep down. Is it normal knowing that the website is protected?
  2. I am not hacking the website; its just that my mentor wanted me to know if I or ZAP has the ability to perform security testing with our website even if it is protected. Is it really possible? If so, how?

I hope that someone would enlighten me with this, because so far, I haven't found any answers yet. Thank you!

Make sbt constant having a dependency included in Test and Integration Test

How to state that a library should be used for Test and IntegrationTest without falling back to strings like "test,it"?

Example:

  "org.scalamock" %% "scalamock-scalatest-support" % "3.3.0" % Test,
  "org.scalatest" %% "scalatest" % scalaTestVersion % "test,it" //<- how to make this safer

jeudi 29 septembre 2016

How to check if Gatling's session variable exists outside of exec block?

My case is quite simple. I have a REST call defined in Scala class - BackendApi:

def eventPathTreeCall(request: EventPathTreeRequestBuilder): HttpRequestBuilder = {
    val url = request.build()
    http(url).get(url).headers(httpGetHeaders())
  }

This call is used by two scenarios - one simulating loading a webpage, and other just testing REST calls. Depending on which scenario is making the call, I need different request headers. For loading web page scenario I need to pass X-CSRF-TOKEN, but I do not want to send it when executing second scenario. What I wanted to achive, is to have an if statement, checking if csrf-token variable is defined in Gatling's session. My first thought was to use Gatling EL:

def httpGetHeaders(): Map[String, String] = {
 val map = collection.mutable.Map(
  "Etag" -> "",
  "X-Forwarded-For" -> "127.0.0.1",
  "X-Origin-Id" -> "3",
  "X-Requested-With" -> "XMLHttpRequest",
  "Pragma" -> "no-cache",
  "Cache-Control" -> "no-cache",
  "Connection" -> "keep-alive")
 if (!"${csrf-token.isUndefined()}".toBoolean)) map.put("X-CSRF-Token", "${csrf-token}")
 map.toMap
}

Unfortunately it does not work, I get an exception about parsing boolean.

Caused by: java.lang.IllegalArgumentException: For input string: "${csrf-token.isUndefined()}"

So it is clear that Gatling's expression is not evaluated. When I have created a var with headers in the same class, and tried to use expressions in it - they were populated correctly:

val getHeaders = Map(
"Etag" -> "",
"X-CSRF-Token" -> "${csrf-token}",
"X-Forwarded-For" -> "127.0.0.1",
"X-Origin-Id" -> "3",
"X-Requested-With" -> "XMLHttpRequest",
"Pragma" -> "no-cache",
"Cache-Control" -> "no-cache",
"Connection" -> "keep-alive")

If my idea is wrong, please tell me how to use session variable value outside of gatling exec blocks, and base test's logic on these values in Scala code.

Excel generate probabilities

I have a list of users in an excel sheet. Corresponding to each user, I need to generate a column that shows the probability of some event occurring. This is a decimal number of 4 digit precision (0.1234).

I need a way to randomly generate this 4-digit precision probability column such that all the probabilities add upto 1.

I am able to do this based on percentage, but for the testing purpose that I am using this, it would be more effective if it were as stated above. Also a drawback of the method that I am using is that formula I use gives more weightage to the users at the beginning than towards the end.

IS there a better way I can achieve this in excel? What all could be good ways to achieve this?

FactoryGirl set updated_at attribute in factory

Using FactoryGirl 4.7.0, I have a factory that I want to specify the updated_at attribute to a date in the past.

factory :living_arrangement do

    trait :expired do
        updated_at Date.new(2012, 3, 6)
        # or
        updated_at { Date.new(2012, 3, 6) }
    end
end

However these are not working. The factory updated_at attribute keeps getting set back to Date.now.

How do I get this to work?

CakePhp Tests and Cookies

I just started working at a company. There is a bunch of controller tests in the app/Test/Case/Controller folder that get launched whenever we commit files. The problem is that there are cookies created that cause the tests to fail. Is there some way that I destroy all cookies and session variables before tests get run?

Django: Managing several related test states in Django

Using Django:

I need to create (by inserting some rows into an empty (is it really created empty?) DB) a state X of the DB.

Then I need to run a test against this state.

Then I need to create a state Y by applying some modifications to state X and run another test against Y.

Then I may need to create more test states based on X and/or Y and run tests for them.

How to do this with Django testing framework?

Using Jenkins for load tests

I'm using JMeter for load test and want to integrate my testing with Jenkins for automated testing.

I'd like to use Jenkins for two things.

  1. I have one big script and several scenarios which only deviate in number of threads and ramp-up time. I'd like jenkins to use a master script, edit these two variables, and run my scenarios in sequence.

  2. These scenarios produce log files, which on completion I'd like to move and rename with a counter on the end (must be unique) ex. JMeter_Load_{COUNTER}

Can/should I do this with Jenkins, or should I just use scripts and crontab?

Thanks for any insights on this.

How can I write the unit test with rewire or mocha for following nodejs code in effective manner?

I have read some tuts related to nodejs testing mostly with rewire and mocha but unfortunately cannot understand how to start.. So please help me by giving some examples for following code snippet and help me to write my first tests... Thanks in advance .

let request = require("request");
let cheerio = require("cheerio");

function scrapUris(uri, selector, cb, baseUri) {
let rUris = [];

request(uri, function(error, response, body) {

    if (body) {
        let $ = cheerio.load(body);
        $(selector).map((index, elem) => {
            let href = $(elem).attr('href')
                // rUris.push(baseUri + href)
            baseUri ? rUris.push(baseUri + href) : rUris.push(href);
        })

        cb(rUris)
    } else if (error) {
        console.log("Error Occurred In HTML Parsing :", error)
        console.log("Requested URI :", uri)
        console.log("Received content :", body)
    } else {
        console.log("Requested URI :", uri)
        console.log("Received content :", body)
    }
})
}

module.exports = scrapUris;

How I know if one fragment is displayed (Test UI)

If one of my fragments, rattingfragment, I have to perform click. If not, do other action.

How I know this is the fragment on my screen?

Android UI Tests.

Karma - Use PhantomJS instead of Chrome

I'm trying to set up automated testing with Karma. Although I ran into a problem.

npm start or npm install give me this error:

> concurrently "npm run tsc:w" "npm run lite"

[0] /c: /c: is a directory
[1] /c: /c: is a directory
[0] npm run tsc:w exited with code 126
[1] npm run lite exited with code 126

npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Ivar\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.5.0
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! angular-quickstart@1.0.0 start: `concurrently "npm run tsc:w" "npm run lite" `
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-quickstart@1.0.0 start script 'concurrently "npm run tsc:w" "npm run lite" '.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the angular-quickstart package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     concurrently "npm run tsc:w" "npm run lite"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs angular-quickstart
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls angular-quickstart
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:

Before they gave me:

> karma start karma.conf.js

29 09 2016 16:49:27.659:WARN [watcher]: Pattern "C:/Users/Ivar/documents/school/stage/workspace/webapplicatie/systemjs.config.extras.js" does not match any file.
29 09 2016 16:49:27.679:WARN [watcher]: Pattern "C:/Users/Ivar/documents/school/stage/workspace/webapplicatie/app/**/*.css" does not match any file.
29 09 2016 16:49:27.691:WARN [watcher]: Pattern "C:/Users/Ivar/documents/school/stage/workspace/webapplicatie/test/**/*.ts" does not match any file.
29 09 2016 16:49:27.692:WARN [watcher]: Pattern "C:/Users/Ivar/documents/school/stage/workspace/webapplicatie/test/**/*.js.map" does not match any file.
29 09 2016 16:49:28.158:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/
29 09 2016 16:49:28.159:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
29 09 2016 16:49:28.166:INFO [launcher]: Starting browser PhantomJS
29 09 2016 16:49:29.956:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#GGY-X69uV6wlYJOnAAAA with id 60252055
29 09 2016 16:49:30.387:WARN [web-server]: 404: /base/node_modules/systemjs/dist/system-polyfills.js
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'System.config')
  at karma-test-shim.js:30

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'System.config')
  at karma-test-shim.js:30

npm ERR! Test failed.  See above for more details.

while in node_modules/systemjs/dist the sytem-polyfills.js does exist.

Now my karma config code:

module.exports = function(config) {

  var appBase    = 'app/';       // transpiled app JS and map files
  var appSrcBase = 'app/';       // app source TS files
  var appAssets  = '/base/app/'; // component assets fetched by Angular's compiler

  var testBase    = 'test/';       // transpiled test JS and map files
  var testSrcBase = 'test/';       // test source TS files

  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    plugins: [
      require('karma-jasmine'),
      require('karma-phantomjs-launcher'),
      require('karma-jasmine-html-reporter'), // click "Debug" in browser to see it
      require('karma-htmlfile-reporter') // crashing w/ strange socket error
    ],

    customLaunchers: {
      // From the CLI. Not used here but interesting
      // chrome setup for travis CI using chromium
      Chrome_travis_ci: {
        base: 'Chrome',
        flags: ['--no-sandbox']
      }
    },
    files: [
      // System.js for module loading
      'node_modules/systemjs/dist/system.src.js',

      // Polyfills
      'node_modules/core-js/client/shim.js',
      'node_modules/reflect-metadata/Reflect.js',

      // zone.js
      'node_modules/zone.js/dist/zone.js',
      'node_modules/http://ift.tt/1KReNIi',
      'node_modules/http://ift.tt/2c7PMID',
      'node_modules/http://ift.tt/2cGDBrq',
      'node_modules/http://ift.tt/1KReLA0',
      'node_modules/http://ift.tt/2anIl3w',
      'node_modules/http://ift.tt/2b8mEkP',

      // RxJs
      { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
      { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },

      // Paths loaded via module imports:
      // Angular itself
      {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
      {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},

      {pattern: 'systemjs.config.js', included: false, watched: false},
      {pattern: 'systemjs.config.extras.js', included: false, watched: false},
      'karma-test-shim.js',

      // transpiled application & spec code paths loaded via module imports
      {pattern: appBase + '**/*.js', included: false, watched: true},
      {pattern: testBase + '**/*.js', included: false, watched: true},


      // Asset (HTML & CSS) paths loaded via Angular's component compiler
      // (these paths need to be rewritten, see proxies section)
      {pattern: appBase + '**/*.html', included: false, watched: true},
      {pattern: appBase + '**/*.css', included: false, watched: true},

      // Paths for debugging with source maps in dev tools
      {pattern: appSrcBase + '**/*.ts', included: false, watched: false},
      {pattern: appBase + '**/*.js.map', included: false, watched: false},
      {pattern: testSrcBase + '**/*.ts', included: false, watched: false},
      {pattern: testBase + '**/*.js.map', included: false, watched: false}
    ],

    // Proxied base paths for loading assets
    proxies: {
      // required for component assets fetched by Angular's compiler
      "/app/": appAssets
    },

    exclude: [],
    preprocessors: {},
    // disabled HtmlReporter; suddenly crashing w/ strange socket error
    reporters: ['progress', 'kjhtml'],//'html'],

    // HtmlReporter configuration
    htmlReporter: {
      // Open this file to see results in browser
      outputFile: '_test-output/tests.html',

      // Optional
      pageTitle: 'Unit Tests',
      subPageTitle: __dirname
    },

    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false
  })
}

Karma shim

// #docregion
// /*global jasmine, __karma__, window*/
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.

// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
// Error.stackTraceLimit = Infinity; //

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

var builtPath = '/base/app/';

__karma__.loaded = function () { };

function isJsFile(path) {
  return path.slice(-3) == '.js';
}

function isSpecFile(path) {
  return /\.spec\.(.*\.)?js$/.test(path);
}

function isBuiltFile(path) {
  return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
}

var allSpecFiles = Object.keys(window.__karma__.files)
  .filter(isSpecFile)
  .filter(isBuiltFile);

System.config({
  baseURL: '/base',
  // Extend usual application package list with test folder
  packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },

  // Assume npm: is set in `paths` in systemjs.config
  // Map the angular testing umd bundles
  map: {
    '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
    '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
    '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
    '@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
    '@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
    '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
    '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
    '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
  },
});

System.import('systemjs.config.js')
  .then(importSystemJsExtras)
  .then(initTestBed)
  .then(initTesting);

/** Optional SystemJS configuration extras. Keep going w/o it */
function importSystemJsExtras(){
  return System.import('systemjs.config.extras.js')
  .catch(function(reason) {
    console.log(
      'Warning: System.import could not load the optional "systemjs.config.extras.js". Did you omit it by accident? Continuing without it.'
    );
    console.log(reason);
  });
}

function initTestBed(){
  return Promise.all([
    System.import('@angular/core/testing'),
    System.import('@angular/platform-browser-dynamic/testing')
  ])

  .then(function (providers) {
    var coreTesting    = providers[0];
    var browserTesting = providers[1];

    coreTesting.TestBed.initTestEnvironment(
      browserTesting.BrowserDynamicTestingModule,
      browserTesting.platformBrowserDynamicTesting());
  })
}

// Import all spec files and start karma
function initTesting () {
    console.log("init testing");
  return Promise.all(
    allSpecFiles.map(function (moduleName) {

        console.log("module: "+moduleName);
      return System.import(moduleName);
    })
  )
  .then(__karma__.start, __karma__.error);
}

last but not least package.json

{
  "name": "angular-quickstart",
  "version": "1.0.0",
  "description": "QuickStart package.json from the documentation, supplemented with testing support",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "docker-build": "docker build -t ng2-quickstart .",
    "docker": "npm run docker-build && docker run -it --rm -p 3000:3000 -p 3001:3001 ng2-quickstart",
    "pree2e": "npm run webdriver:update",
    "e2e": "tsc && concurrently \"http-server -s\" \"protractor protractor.config.js\" --kill-others --success first",
    "lint": "tslint ./app/**/*.ts -t verbose",
    "lite": "lite-server",
    "postinstall": "typings install",
    "test": "tsc && concurrently \"tsc -w\" \"karma start karma.conf.js\"",
    "test-once": "tsc && karma start karma.conf.js --single-run",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings",
    "webdriver:update": "webdriver-manager update"
  },
  "license": "ISC",
  "dependencies": {
    "@angular/common": "~2.0.1",
    "@angular/compiler": "~2.0.1",
    "@angular/core": "~2.0.1",
    "@angular/forms": "~2.0.1",
    "@angular/http": "~2.0.1",
    "@angular/platform-browser": "~2.0.1",
    "@angular/platform-browser-dynamic": "~2.0.1",
    "@angular/router": "~3.0.1",
    "@angular/upgrade": "~2.0.1",

    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25",
    "angular2-in-memory-web-api": "0.0.20",
    "bootstrap": "^3.3.7"
  },
  "devDependencies": {
    "concurrently": "^3.0.0",
    "lite-server":"~2.2.2",
    "canonical-path": "0.0.2",
    "http-server": "^0.9.0",
    "tslint": "^3.15.1",
    "lodash": "^4.16.2",
    "jasmine-core": "~2.5.2",
    "karma": "^1.3.0",
    "karma-phantomjs-launcher": "^1.0.0",
    "karma-cli": "^1.0.1",
    "karma-htmlfile-reporter": "^0.3.4",
    "karma-jasmine": "^1.0.2",
    "karma-spec-reporter": "0.0.13",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^3.3.0",
    "rimraf": "^2.5.4",
    "phantomjs-prebuilt": "^2.1.7",
    "typescript": "^2.0.3",
    "typings": "^1.4.0"
  }
}

Sorry for the amount of code but I can't seem to find the problem myself.

Testing iOS-app on device while offline

I have a paid Apple developer account. I'm using Xcode 8.0 with iOS 10.0.1 on an iPhone 6 plus.

Starting the app on the device works, I verified the developer app certificate on the iPhone.

So I want to test my app while device is offline on starting the app. In Xcode I got the message:

"Verify the Developer App certificate for your account is trusted on your device. Open Settings on iPhone Plus and navigate to General -> Device Management, then select your Developer App certificate to trust it."

I have to go online to verify. Then I go offline again and same thing happens.

My question: How to test an app on device while offline on starting the app?

Selenium grid opens less sessions than specified in the thread-count testng xml file

Using TestNG with Selenium Grid 2.53.0 produces some unexpected behavior. The thread-count is set to 38 and the maxSessions in the grid is 100 but still got only 26 sessions open on the grid in parallel (I expect 38). Number of available nodes is 50.

echo "ext. key 3587d14f-78ea-41c7-aa64-e1bd68c665d4, ext. key 544ccb82-ae55-4ef7-9552-63dd6ba13968, ext. key f8be5689-0f3b-4649-a68f-f76731c5684f, ext. key 6f83ff7d-fa0a-4e24-84bc-f4ece7e05e06, ext. key 6e667c45-616e-4dd3-ba75-bb541eaeab7f, ext. key da278a67-1940-4f01-a0d3-e98fbfe9d614, ext. key afd9d82b-de1d-424d-b31d-2e4d1a405203, ext. key 63a72623-a11a-4e0a-afd0-c025b90e3af1, ext. key 612fde24-ef12-4347-bd40-f4f61eb80f20, ext. key a33e83a5-5575-4e65-b191-a083098f9c96, ext. key 12d81fc0-a232-4d8a-82e0-ab59253ee31c, ext. key 0ef3baad-674e-4838-b1c8-a044300b9914, ext. key 0f543047-ca7c-4807-9de9-63bb768a28c0, ext. key e341098f-f005-4e03-a927-705c42d37ce0, ext. key 746c9707-cbbd-4d18-8005-06c8aa585156, ext. key 3db3dec2-83c1-493a-87d2-2114cedf67a7, ext. key e4b64960-35f0-450d-9249-9526cee8312f, ext. key a13178a5-ee35-4640-8318-f3d2b4baf44c, ext. key 59d364fa-3a1b-4aa2-bedb-f288fd0d7d9b, ext. key f9273ec3-ae9e-48d0-81cc-3b781eb5b683, ext. key 41919e0b-d01a-45c6-aa06-ab0a3240212d, ext. key 84441daa-d673-4859-8177-ccc4a90f5fd8, ext. key f2a732d8-201d-48a8-9382-19fcf8ba5749, ext. key fb2ab9c8-78c0-419b-8a62-577920e759cb, ext. key 847892ef-16ca-49c3-86d6-74b0a2f1f5d9, ext. key 7729c3dd-8124-4cdf-b63a-e1b16e1f6178" | tr "," "\n" | wc -l
26

Can one explain what's the reson behind this behavior?

Thanks.

run multiple gradle tasks in one jenkins job even when fail

Is there a way to run multiple gradle (junit tests) tasks in one jenkins job? jenkins should run the next task even the previous one failed.

I tried this through the shell:

./gradlew clean &
./gradlew myTest -Pserver=serverA &
./gradlew myTest -Pserver=serverB &
./gradlew myTest -Pserver=serverC -Pfollow=false

Here jenkins would just run the first line and stop after that.

Then I tried to use the multiple conditions plugin. This one works until one job fails.

Symbolic Execution vs. Genetic Algorithm

In order to generate verification and test-case generation what is the difference between using symbolic execution and genetic algorithm? I heard genetic algorithm implementation is easier than symbolic execution, Is it true? What is the advantage of implementing symbolic execution rather than genetic algorithm?

On Target Unit testing for STM32L0x3 using IAR

I want to have a test frame work in my IAR Project. The processor is an STM32L0.

What I've tried:

  • http://ift.tt/Tu5QLq followed the turoial at : http://ift.tt/2dBXjB8 Didn't work because there is only 64K Flash & 8K RAM

    enter image description here

    and its not enough for this framework

  • http://ift.tt/2dBX3lP I tried to intigrate into IAR Embedded workbench but had a lot of compiler errors also not enough space so I tried to run it on my Desktop. This doesn't work because it has too many Hardware dependencies in the code..

  • Next I tried to just make "Pseudo" unit testing by putting a test routine at boot of the device which can be switched on and off by precompiler directives.

Like this (not finished):

#if PREFORM_TESTS
    TEST_run();
#endif  

And then with files:

#include "testAll.h"
#include "testEvent.h"
#include "stm32l0xx_hal.h"

void TEST_run(){
  TEST_EVENT_run();
}
void assert_failed(uint8_t* file, uint32_t line){
  while(1);  
}

#include "testEvent.h"
#include "testAll.h"
#include "event.h"
#include "stm32l0xx_hal.h"

void test_add_event();

void TEST_EVENT_run(){
    test_add_event();
}

void test_add_event(){
  ASSERT(1); 
}

How can I run Unit Tests on my STM32L0x3?

Tools to compare data in tables form SQL,Oracle,SAP with Tables in SQL server

I do ETL Testing.The Application I work on loads data from Oracle,SQL,J.D.Edwards and SAP into SQl server. I wanted to test for data that is loaded into the sql server for any data mismatches. Is there any tools out there with which we can compare the data from tables in Oracle,SQL,J.D.E edwards with the Table in sql server.

I have read few posts online and in stack overflow itself but they are suggesting tools that compare the data in sql-sql.I wanted to know if there are any tools that can compare data from different types of databases.

Using Enzyme simulate on custom events?

It is possible to use Enzyme's method .simulate() on custom events. For Example:

// Code
<Element onFoo={someFunction}></Elements>

// Test
const element = shallow(<Element>);
element.simulate('foo');

Is this the way custom events should be tested with Enzyme or is it a better approach to use s.th. like:

//Test
const element = shallow(<Element>);
element.props.onFoo()

Disable or limit website crawler tests and tour tests

I have some Travis jobs failing because:

  1. href links with phone number such as <a href="tel:+54334543554" title="Call us"> tel: protocol are treated as relative links, and fail like

2016-09-29 09:20:46,029 7166 INFO customer_db werkzeug: 127.0.0.1 - - [29/Sep/2016 09:20:46] "GET /path/to/page/tel:+41228273777 HTTP/1.1" 404 - 2016-09-29 09:20:46,032 7166 ERROR customer_db openerp.addons.website.tests.test_crawl: FAIL

  1. we removed some elements on website frontend, like the dropdown for adding contents #content-menu-button, and fail like:

2016-09-29 09:21:21,516 7166 INFO customer_db openerp.tests.common: phantomjs: Tour 'event' Step: 'Create an Event' (19ms) 2016-09-29 09:21:32,574 7166 ERROR customer_db openerp.tests.common: phantomjs: error: Can't reach the next step tour: event step: 1: 'Add Content' href: http://127.0.0.1:8069/ referrer: element: false "#content-menu-button"

Is there a way to disable such tests or to limit them without patching the tests themselves?

how to mock $_SERVER[QUERY_STRING]

I created a Middleware which should redirect if in the Url has a Parameter like 'redirect=http://example.de'. It is necessary that I use $_SERVER['QUERY_STRING'] to geht the Query. I am not allowed to use it from the $request Parameter. I wrote the Middleware and everything works fine. I failed at the Unit Testing, because I was not able to mock the request so that the $_SERVER['QUERY_STRING'] Variable is set. Long Story short: I don't get a Value in $_SERVER['QUERY_STRING'] when I mock the request. So I was searching for solutions and found this Question. I implemented this code like this:

public function testMyMiddleware(String $url) {

        $redirect = new MyMiddleware();
        $environment = Environment::mock([
                'REQUEST_METHOD' => 'GET',
                'REQUEST_URI' => 'http://ip/middle?param=123&redirect=https%3A%2F%2Fgoogle.de%2F',
                'QUERY_STRING'=> 'param=124&redirect=' . $url]
        );
        $request = Request::createFromEnvironment($environment);
        $response = new Response();

        $mock = function (ServerRequestInterface $req, ResponseInterface $res) {
            return $req;
        };
        $response = $redirect($request, $response, $mock);
        $this->assertSame($response->getHeader('Location'), [urldecode($url)]);
        $this->assertSame($response->getStatusCode(), 302);
}

Unfortunately I still got the same Problem. Also found this, but it didn't help either.

Testing a module with input() and print() inside - using TestCase

Situation:

A students task is to write a python script, doing something with only input() and print().

Example task: "Write python script that asks for number 'n' and prints string of 'n' stars."

He writes a script like this:

solution.py

n = int(input())
print('*' * n)

I want to write python module, that tests that his script is working correctly.

My solution till now is to do this:

test.py from io import StringIO import sys

sys.stdout = StringIO()
sys.stdin = StringIO(str(2))

import riesenie

s = sys.stdout.getvalue()
if s != '**' * 2 + '\n':
    raise Exception('WRONG')
else:
    print("OK", file=sys.stderr)

BUT, I would like to achieve this behaviour using TestCase. Something like:

test.py from unittest import TestCase

class TestSolution(TestCase):
    def test_stars(self):
        sys.stdout = StringIO()
        sys.stdin = StringIO(str(2))
        import riesenie
        s = sys.stdout.getvalue()

        self.assertEqual('**', s)

But this is not working.

Is there a way to achieve this? Thank you in advance.

GoConvey: Support build tags #249

I'm using GoConvey to run some tests, however I'm having issues in order to have it running tests that are flagged with // +build integration and that uses ldflags at compilation time. This is how I run this tests without goconvey: go test -v -tags=integration -ldflags '-X http://ift.tt/2cDnWU9 -X http://ift.tt/2dteMzR:'

However when I run the same command, but changing to have GoConvey executing it, I'm running into: error: flag provided but not defined: -tags

cmd: goconvey -tags=integration -ldflags '-X http://ift.tt/2cDnWU9 -X http://ift.tt/2dteMzR:'

Any ideas ?

Cheers.

NoSuchWindowException when trying to get a report inside a new window

I have the following in my code:

withWindow({ title == 'Google' }) {
    report "08"
}

And report is leading me to the exception NoSuchWindowException. I've checked if that was a problem of the Window selector and it isn't,After some research I guessed that the problem was that the driver got messed in the way so I stored and switched my driver:

String  mainHandle= driver.getWindowHandle();
driver.switchTo().window('Google');

But I kept getting the same error. So I tried:

driver.get("http://www.google.com");

And it is working but I need to do this dinamycally and automatically because the windows and popups that we are working with are hundreds and with different titles.

How can I achieve that in every windows that opens? We are generating the code with a external tool so I don't need to do "magic", only a driver.get.windowUrl or something like this will work for me.

mercredi 28 septembre 2016

What should I do differently to get crashes on android & iOS app pro live builds?

Always, I test app pro live build on all most running OS versions for crashes, I find and fix crashes, but still after going live, I find some other crashes, which I didn't recognised. What should be in my process Or different ways to get these before. Any tips of yours ...

Thanks.

Testing accessibility using Mac VoiceOver for web pages

I am working on developing/testing accessibility of a web page using VoiceOver [Mac Tool].

Typical workflow I am using is trial and error,

  1. Do changes to HTML
  2. Open page in browser
  3. Turn on VoiceOver and test and again #1

What I understand is VoiceOver convert/see HTML/Webpage in text form and starts reading it. I hope how it does it would make it easy for me to understand how to make process easy.

So I want to know if there is any tool or utility or guidelines which could assist me to see HTML/Webpage the way VoiceOver does. I mean tool which take html as input and then output text file like VoiceOver (JUST to understand what changes affects VoiceOver in what way quickly).

Any inputs will be really helpful.

How to output verbose doctest to file within a program

I am trying to write a python program where at the end of the program, after the if __name__ == "__main__": dunder the program outputs the result of executing the file with the -v flag set. So far I have this:

if __name__ == "__main__":
import doctest
import subprocess
import os
doctest.testmod()
with open("is_float_documentation.txt", "w") as doc:
    subprocess.call(["cd", "'" +
                     os.path.dirname(os.path.realpath(__file__)) + "'"])
    subprocess.call(["python", ".\isfloat.py", "-v"])

but, this does not work perhaps due to some strange permissions errors that I am experiencing.

How to mock angular2 platform-browser Title component for testing purpose

I am writing unit tests for angular2 component with jasmine. I will like to test if my document title as been set to a specific value when my component is instanciate.

Here is my component

import { Component } from '@angular/core';
import { Title }     from '@angular/platform-browser';

@Component({
  selector: 'cx-account',
  templateUrl: 'app/account/account.component.html',
})
export class AccountComponent {
  public constructor(private titleService: Title ) {
    titleService.setTitle("Account");
  }
}

Here what I have wrote for testing but it is not working. titleService.getTitle() gives me Karma debug runner page title.

import { TestBed }      from '@angular/core/testing';
import { Title, By }           from '@angular/platform-browser';
import { AccountComponent } from './account.component';

describe('AppComponent Tests', function () {
  let titleService: Title = new Title(); 
  beforeEach(() => {
    TestBed.configureTestingModule({
        declarations: [AccountComponent],
        providers:    [ {provide: Title } ],      
    });
   let fixture = TestBed.createComponent(AccountComponent);

   });

  it('Title Should be Account', () => {
    expect(titleService.getTitle()).toBe('Account');
  });      
});

Karma output is : Error: Expected 'Karma DEBUG RUNNER' to be 'Account'.

Test Maangement tool for protractor and BDD with cucumber

Best test case management tool for BDD and support to Cucumber and for protractor test Automation. I come through the bunch of test management tool like zephyr for jira, Hiptest for jira server, Qmetry. I need help on the this.I am working selenium protractor UI automation and looking test management tool.please let me know your feed back.

python/django MagicMock return return value not behaving like I expect

I havr this try/except loop in a model method that I am trying to write tests for...

try:
    wiktionary_url = "http://%s.wiktionary.org/wiki/FILE:%s-%s.ogg" \
        % (self.language.wiktionary_prefix, url_sub_path, self.name)
    wiktionary_page = urllib2.urlopen(wiktionary_url)
    wiktionary_page = fromstring(wiktionary_page.read())
    file_url = wiktionary_page.xpath(
                "//*[contains(concat(' ', @class, ' '), ' fullMedia ')]/a/@href")[0]
    file_number = self.get_num(
        self.definition_set.all()[0].search_existing_audio())
    print file_number + " file num"
    relative_path = '%s/%s%s.ogg' % (path, self.name, file_number)
    full_path = '%s/%s' % (settings.MEDIA_ROOT, relative_path)
    popen("wget -q -O %s 'http:%s'" % (full_path, file_url))
    made = self.definition_set.all()[0].convert_to_mp3(full_path)
except Exception as exc:
    print str(exc)
    return False

and I am trying to write a test for it while mocking some of the function in it.

@patch("lang_api.models.urllib2.urlopen")
@patch("lang_api.models.fromstring")
@patch("lang_api.models.Definition.convert_to_mp3")
@patch("lang_api.models.os.popen")
def test_get_wiktionary_audio(self, popen, convert_to_mp3, fromstring, urlopen):
    # I need to mock another function in the actual method
    fromstring.return_value = MagicMock(return_value='string')
    test = self.things.model['word'].get_wiktionary_audio('en')
    popen.assert_called()
    convert_to_mp3.assert_called()

when I try something similar in the python intepreter it works perfectly. but when this test runs it outputs this error.

sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `wget -q -O /Users/Jeff/Development/langalang/langalang/../media/study_audio/eng/words/table1.ogg 'http:<MagicMock name='fromstring().xpath().__getitem__()' id='4361699216'>''

so my return value statements are not being read properly but I cannot see what is happening.

How to unit test class that loads many entities from database

Let's say I have a relational data model:

InputContainer 1-* Input 1-1? InputInfo 1-1 Link 1-1 OutputInfo 1-1? Output 1-* OutputContainer

What exactly are Input, Output doesn't matter, what's important is that for every Input there may be zero or one InputInfo, the same goes for every Output. Inputs and Outputs are grouped in containers - they may be up to say 1024 Inputs per container. Link is used to connect Input to Output, this connection is not always present (when it is then InputInfo and OutputInfo are present too).

This is a legacy model that I cannot change. Now to the problem. I have a class that for given InputContainer (and it's Inputs) should find all linked Outputs and update one of their fields. Then for these updated Outputs I need to find all OutputContainers and update some properties of the container (too preserve invariant's in containers, this will require loading all container Outputs). Properties to update are simple, you may assume that I just change some int value in Output and that OutputContainer contains field that should be sum of these ints. When I implemented domain service that does exactly that, it basically is all about reading data from DB and saving data to DB. All queries are encapsulated in repository methods.

How I can effectively test this class, when I try to write unit-tests it turns out that there is plenty of data to mock/stub and since most logic is in queries I still need some integration tests. Should I in this case relay only on integration tests - but that still doesn't solve problem with huge amount of data that needs to be set up to test this class, and creating this data in test makes test unreadable.

Yikes, this question turned out longer that I expected; To sum up how to unit-test domain services that implement "data intensive" logic?

Rails Engine Controller Test

I have a rails engine that I've created to share Model code between two repositories. Their respective controllers live in their respective repositories. I'm trying to test the controllers, using the machinist gem to generate the factories. But when I try to create my factories I get an uninitialized Constant error, which signifies to me that the models from my rails engine aren't getting properly required. I tried to explicitly require the rails engine gem in my spec_helper.rb file, but I got a file not found error then.

Curious if anyone has dealt with this before?

Michael Hartl's Rails 5 tutorial chapter 10, listing 10.62, error in integration test for delete links and destroying user

Doing last exercise of chapter 10, wild NoMethodError has appeared in listing 10.62 test

test/integration/users_index_test.rb

require 'test_helper'

class UsersIndexTest < ActionDispatch::IntegrationTest

  def setup
    @admin     = users(:michael)
    @non_admin = users(:archer)
  end

  test "index as admin including pagination and delete links" do
    log_in_as(@admin)
    get users_path
    assert_template 'users/index'
    assert_select 'div.pagination'
    first_page_of_users = User.paginate(page: 1)
    first_page_of_users.each do |user|
      assert_select 'a[href=?]', user_path(user), text: user.name
      unless user == @admin
        assert_select 'a[href=?]', user_path(user), text: 'delete'
      end
    end
    assert_difference 'User.count', -1 do
      delete user_path(@non_admin)
    end
  end

  test "index as non-admin" do
    log_in_as(@non_admin)
    get users_path
    assert_select 'a', text: 'delete', count: 0
  end
end

test error

ERROR["test_index_as_admin_including_pagination_and_delete_links", UsersIndexTest, 0.8833864140324295]
 test_index_as_admin_including_pagination_and_delete_links#UsersIndexTest (0.88s)
NoMethodError:         NoMethodError: undefined method `email' for nil:NilClass
            test/test_helper.rb:31:in `log_in_as'
            test/integration/users_index_test.rb:11:in `block in <class:UsersIndexTest>'

Any ideas what could be missed here? Many thanks!

How to set Allow Mock Location on Android Device before executing AndroidTest with uiautomator and espresso?

Basically every time I have to execute an AndroidTest that makes use of mock location provider I need to manually check the box on device emulator: Settings--> mock locations. How to automate this task directly from the android test? Is there any way using espresso/uiautomator/something else?

Deploying iOS application for automation testing

When you do automation testing for an iOS app, is there a way to only deploy the app once, rather than deploying every time you run another test set? I would like to just launch the existing application again in order to avoid the time it takes for login and the synching of data.

Spring boot web application integration tests suite

I have a bunch of integrations tests containing

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SpringBootApp.class)
@WebIntegrationTest(randomPort = true)

The problem i have is the application gets started and stopped for every test class. Is there anyway i can start the application once, run all the integration tests and stop?

How to use NodaTime FakeClock to time travel and test different virtual time instances

For the last 30 mins I've been trying to get my FakeClock to start up at a certain time. I'm using it in a Stock Market app and I just use New York timezone. The stock market closes at 8PM and opens at 4AM, so I thought I could avoid ever dealing with daytime changes (at least for now). And since I'm only concentrating on US stocks, I'd also like to avoid any other timezones and confusion.

Anyways, here is how I'm starting up the app and using the Zoned

var zoneInfo = DateTimeZoneProviders.Tzdb["America/New_York"];
var  NewYorkZonedClock = new ZonedClock((IClock)SystemClock.Instance, zoneInfo, CalendarSystem.Iso);

For my tests, I want to set time to July 1, 2016 03:59:59 am. FakeClock constructor argument is of type Instance. I tried to get this instance a bunch a different ways and I keep getting more and more confused and not sure what's the safest and correct way of doing this.

 FakeClock.FromUtc(2016, 07, 01, 03, 59, 59);

First I tried this and couldn't find a natural way without manually moving the time to adjust for the zoneoffset.

 var dateTimeInstance=new LocalDateTime(2016, 07, 01, 03, 59, 59);
 var fakeClock = new     FakeClock(dateTimeInstance.InZone(DateTimeZoneProviders.Tzdb["America/New_York"]))

I thought this would definitely work but the method InZone has a second parameter called ZoneLocalMapping and after poking around in the NodaTime library and googling I can't make sense of what's expected here.

Finally I found a way to make it compile time acceptable by using InZoneLeniently()

            var fakeClock = new FakeClock(new LocalDateTime(2016, 07, 01, 03, 59, 59).InZoneLeniently(zoneInfo).ToInstant());

But, there is also an InZoneStrictly(). Which one should I be using?

Michael Hartl's Rails 5 tutorial chapter 10 listing 10.56 Testing that the admin attribute is forbidden

I was trying to pass the exercise in listing 10.56 and test if the admin attribute is forbidden. I added admin parameter in

app/controllers/users_controller.rb

def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation,
                                   :admin)
end

also, filled necessary parts in

test/controllers/users_controller_test.rb

test "should not allow the admin attribute to be edited via the web" do
      log_in_as(@other_user)
      assert_not @other_user.admin?
      patch :update, id: @other_user, user: { password: "",
                                              password_confirmation: "",
                                              admin: true }
      assert_not @other_user.reload.admin?
 end

Still, I am getting unknown error after test:

ERROR["test_should_not_allow_the_admin_attribute_to_be_edited_via_the_web", UsersControllerTest, 3.2600422599352896]
 test_should_not_allow_the_admin_attribute_to_be_edited_via_the_web#UsersControllerTest (3.26s)
URI::InvalidURIError:         URI::InvalidURIError: bad URI(is not URI?): http://www.example.com:80update
            test/controllers/users_controller_test.rb:37:in `block in <class:UsersControllerTest>'

Anyone here was dealing with the same problem?

Many thanks for any help)

Ngrok setup an SSL local tunnel to an existing Vhost

I'm trying t use Ngrok to create a local tunnel to an SSL Virtual host I have on my local machine, but can't seem to get it to work.

My Vhost works perfectly. The site is http://ift.tt/1udZs5C

Any of the command I try to use to predefine the pointing url on Ngrok, e.g.

./ngrok http -host-header=rewrite local.mysite.com:443

or

./ngrok http -subdomain=local.mysite.com local.mysite.com:443

always seems to return:

Bad Request Your browser sent a request that this server could not understand. Reason: You're speaking plain HTTP to an SSL-enabled server port. Instead use the HTTPS scheme to access this URL, please.

I get that this is happening because I am trying to access a HTTPS connection via a HTTP call but I can't see alternatives in the ngrok docs.

http://ift.tt/1ielpD4

The calculation of the testing metrics

The table below shows the type of defects found at different phases in a project

enter image description here

1.What is the number of defects on phase entry in design phase and coding phase?

2.What is the number of defects escaped to the next phase?

3.What is the Defect Removal Efficiency(DRE) in design and coding phase?

How to determine the reason why Firefox has poor performance on my web application?

I am developing a complex web application, which is working fine on Chrome and IE, but recently has developed huge performance issues on Firefox which lead us to block its usage completely to avoid a poor UX while the problem isn't solved.

Below is a screenshot of the Firefox profiler: enter image description here The file is available here for deeper inspection (2MB JSON)

As I can understand from this, it seems that Firefox is taking a tremendous amount of time recalculating the layout, which seems to happen on each user interaction with the application.

How do I interpret all this data? How can this help me trace the origin of the problem and remove all of these layout recalculation?

Are Windows 10 containers suitable for application/acceptance testing?

I'm trying to figure out how to do some software testing on a Windows 10 machine and I'm not sure if what I want to do is possible with Docker or some other technology. If anyone has any advice on if it is possible or not, and what technology I'll need to do it that would be great, more than happy to go of and investigate if I know I'm going in the right direction.

Essentially I want to build a container which uses my main Windows 10 installation as a basis but then has isolated containers which would:

  • Look and behave as if they are part of the same Windows 10 install
  • Be isolated from other containers also running in terms of applications and folder structure. I'd like to be able to start up an application in the container, give it access to folders on the main install as well as within the container and then have it pass out results back to the main Windows install.
  • Have the ability to reset back to its original image state so when I launch the container at some point in the future, any applications or files that were installed into the container, are not there. I want to go back to the original state defined in the image (probably just a folder structure as any default applications would be installed on the base Windows install).

Does that make sense? I'd be interested to hear any thoughts on whether this is possible or not. I've been trying to do it for a few days without luck, using Docker, Docker-Machine, Hyper-V together with blogs/tutorials found online.

Thanks,

PH

How to implement an "assert_difference" for ExUnit

I'd like to test how a function changes something in the database. I'm struggling with an ExUnit equivalent of the following ActiveSupport::TestCase test case:

test "creates a database record" do
  post = Post.create title: "See the difference"
  assert_difference "Post.published.count" do
    post.publish!
  end
end

The RSpec version is more elegant and, because of its use of lambdas, something I thought was portable to Elixir/ExUnit.

it "create a database record" do
  post = Post.create title: "See the difference"
  expect { post.publish! }.to change { Post.count }.by 1
end

Is there a more elegant (read: functional) way to do it than this:

test "creates a database record", %{conn: conn} do
  records_before = count_records
  post(conn, "/articles")
  records_after  = count_records

  assert records_before == (records_after - 1)
end

defp count_records do
  MyApp.Repo.one((from a in MyApp.Article, select: count("*"))
end

Kotlin - Mockito cannot mock/spy (Spring REST API)

Since all classes in Kotlin are final by default, and Mockito can't spy on final classes:

Cannot mock/spy class bye.persistence.jdbcTrial
Mockito cannot mock/spy following:
  - final classes
  - anonymous classes
  - primitive types

And this guide (6 July, Danny Preussler) is saying that a framework is neccessary to resolve this issue.

Now was I wondering, is it possible to test a REST API (using Spring MockMvc). Below is my tester code:

package byeTest.persistenceTest
import bye.domain.User
import bye.persistence.jdbcTrial
import bye.spring.GreetingController
import byeTest.persistenceTest.RestAPITest.RootConfig
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.BDDMockito.given
import org.mockito.Mockito
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.MediaType
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
import org.springframework.test.context.web.WebAppConfiguration
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.web.context.WebApplicationContext

@RunWith(SpringJUnit4ClassRunner::class)
@ContextConfiguration(classes = arrayOf(RootConfig::class))
@WebAppConfiguration
open class RestAPITest {
    var mockMvc: MockMvc? = null;

    @Autowired
    var wac : WebApplicationContext? = null;

    @Autowired
    var jdbcTrial : jdbcTrial? = null

    @Autowired
    var todoServiceMock : GreetingController? = null;

    @Before
    open fun setup(){
        mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build()
        given(this.jdbcTrial?.getUserById(2)).willReturn(User(2,"uname","typ"));

    }



    @Test
    open public fun find_2(){
        mockMvc!!.perform(get("/user/2").accept(MediaType.APPLICATION_JSON))

            .andExpect(content().string("{\"id\":2,\"username\":\"uname\",\"usertype\":\"typ\"}"))


    }

    @Configuration
    open class RootConfig{
        @Bean
        open fun jdbcTrial():jdbcTrial{
            return Mockito.mock(jdbcTrial::class.java)
        }
    }
}

I set all the functions and classes used to open since according to the kotlin docs this is the exact opposite of final. But using this (everywhere) still throws the exception mentioned above.

How to go back to command prompt after writing scenario for behat testing?

Another command prompt window opens to write scenario, and the earlier window is not visible and hence i'm not able to enter any commands after writing the scenario.

gradle compiles but does not run tests

I'm trying to create a new gradle project for just testing some code but I can't run the test cases.

My folder structure looks like this:

- src
    - main
        - groovy
        - java
        - resources
    - test
        - groovy
        - java
        - resources

My build.gradle:

group 'test'
version '1.0-SNAPSHOT'

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

and a test, that is in src/test/groovy:

import groovy.util.logging.Log
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@Log
@RunWith(JUnit4.class)
class TestA {
    TestA() {
        println "hello"
    }

    @Test
    void "test"() {
        println "a"
        log.info("b")
    }
}

When I'm running ./gradlew.bat test through the command line I get this:

{ test }  » ./gradlew.bat test
:compileJava UP-TO-DATE
:compileGroovy UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestJava UP-TO-DATE
:compileTestGroovy
:processTestResources UP-TO-DATE
:testClasses
:test

BUILD SUCCESSFUL

Total time: 5.333 secs

Everything should be right but nothing gets printed and I don't know why.

How can I load external JSON files into my test in Angular 2?

I'm writing some tests for an Angular 2 app that needs to mock a big JSON structure. I want to put that that JSON in its own file so that I can import it on other tests as well. In using Jasmine with Karma.

Any ideas on how to solve this?

static variable changes through different tests

Why does a private variable changes though different tests?

For my tests I'm using Groovy and JUnit4.

For my example we are assuming that the tests run in the order that I wrote them. Here is an example with output values:

class Email {
    def get() {
        def timestamp = (System.currentTimeMillis() / 10L).toString().replaceAll("\\.", "");
        return "mail." + timestamp + "@test.com"
    }
}

@RunWith(JUnit4)
class TestA {
    private static def email = new Email().get() // e.g. mail.123@test.com
    static def form = [
        email: email,
        password: 12356
    ]

    @Test
    void "firstTest"() {
        println email // prints mail.123@test.com
        println form.email // prints mail.123@test.com
    }
}

@RunWith(JUnit4)
class TestB {
    private static def email = new Email().get() // e.g. mail.456@test.com
    static def form = [
        login: email,
        password: 12356
    ]

    @Test
    void "secondTest"() {
        println email // prints mail.456@test.com
        println form.login // prints mail.123@test.com
    }
}

Why is it like it is and how do I prevent it?

mardi 27 septembre 2016

DRE for the design phase

The number of defects found in design phase = 50 The number of defects found in coding, testing, operation phases = 80 Among the number of defects found after the design phase, 60 of them are introduced after the design phase.

What is the DRE for the design phase?

simple tape js test for redux saga failing with undefined

I've written a few tape tests for my sagas but the most simple examples are consistently failing for the same reason. I have a one line saga:

export function* clearUser(){
    yield* put({type: 'CLEAR_USER'});
}

my tape test is equally simple:

test('clear user saga', (assert)=> {
    const gen = clearUser();
    assert.deepEqual(
        gen.next().value,
        put({type: 'CLEAR_USER'}),
        'clear user should pass to reducer to remove user from state'
    )

    assert.deepEqual(
        gen.next(),
        { done: true, value: undefined },
        'clear user saga should complete'
    )

    assert.end()
});

However, the first assertion fails and says the value is undefined:

  operator: deepEqual
  expected: |-
    { '@@redux-saga/IO': true, PUT: { action: { type: 'CLEAR_USER' }, channel: null } }
  actual: |-
    undefined

I've confirmed I'm importing the saga, and other tests are working, why does this simple test fail?

Python2.7(on Windows) Need to capture serial port output into log files during Python/Robot script run

We are testing networking devices to which test interaction is done using serial ports. Python 2.7 with Windows is used to achieve this using the PySerial module of Python. The scripts are run using Robot framework.

We observe that the Robot logs do not contain the serial device interaction dialogues.

We tried checking on Robot framework forums and it is unlikely that such support exists at Robot framework level.

We need to implement this in Python. How can the following be achieved: I) Basic requirement: All script interaction with the (multiple) test devices on serial port needs to be captured into a log file II) Advanced requirement: while the script is not actively interacting with the test device there has to be continuous background monitoring of the device under test over serial ports for any errors/crashes

Thanks!

Is it possible for a program cannot find the failure by using dynamic testing, but have fault?

Is it possible for a program cannot find the failure by using dynamic testing, but have fault? any simple example?

Please help! thanks.

How can I use Smarty templates with A/B testing?

I am attempting to build a little modification in our code to allow easier A/B testing.

I'd like to know if I can somehow 1. have my regular code under the /templates directory 2. have any a/b code under /templates/_abtests/, but also follow the same hierarchy as the regular code. for example... an ab test can overwrite a file like '/templates/foo.tpl', and use instead '/templates/_abtests/testfoo/foo.tpl'

I tried changing the template directory when in a test. Right before calling the display method, I would check if a user is in a test, and if so, set up the template_dir accordingly. I'd assign an array with the 'ab' directory first, then the default. I am using Smarty2.

the problem with this is that it caches the first instance, and uses that as the template for the baseline and ab test case. ie: i have a parameter to force me into a test bucket, but the template is the same.

thoughts on how to achieve this? goal is to not have to add a bunch of template hooks (if/else) in the templates. and achieve this by simple template/file includes.

Golang test gives inconsistent results when ran in verbose mode

I have a single test function in my _test.go file with a bunch of sub tests. It looks like this:

func MyTest(t *testing.T) { 
    t.Run("Subtest1", func(t *testing.T) {
       ...
    })
    t.Run("Subtest2", func(t *testing.T) {
       ...
    })
}

I run the test with go test and get

PASS
ok      package_path    9.137s

However, I would like to see listed all my subtests in the result. Looking at the Run function in $GOROOT/src/testing/testing.go it looks like I need the test to be chatty.

So I tried to run the test via go test -v but I still do not get the desired output. Instead my test is now failing:

=== RUN   MyTest
api.test: error: expected argument for flag '-t', try --help
exit status 1
FAIL    package_path    0.004s

--help does not show anything about -t

Mocked method (B) in a class calls real method(B) while calling real method(A). Method B is being called in method A

I have been trying to resolve this issue for quite a while now, I am trying to mock methodB() in a class where the real methodB() is being called. I am calling the methodA() which has a call to methodB() inside it. Also, both the methods are in the same class. I have also tried these two links, where the usage of spy() is recommended.

Note: The issue only arises when I try to mock a method in the same class. This does not happen when I try to call a method from a different class, since the mocked implementation of that kicks in. Please help.

Thank you.

Using Mockito to stub and execute methods for testing Use Mockito to mock some methods but not others

Class PolicyTest {
    @Mock    
    @Autowired 
    PolicyService policyServiceHistory;
    List<PolicyDetail> policyDetails = new ArrayList<PolicyDetail>();

@Before
public void setup() {

   policyServiceHistory = mock(PolicyServiceImpl.class);

}

@Test
    public void getPolicyHistory() throws ParseException {

    PolicyServiceImpl policyService = new PolicyServiceImpl();
//mocked the method using the mocked object    
when(policyServiceHistory.getPolicyDetails(anyString(),(Date) any(),anyString())).thenReturn(mockPolicyDetails);
//calling the real method using the real object    
List<PolicyDetail> policyDetails = policyService.getPolicyDetailsHistory(mockCompany);


}


Class PolicyServiceImpl {

          public List<PolicyDetail> getPolicyDetailsHistory() {

        //real method getting called even though its return value is  //mocked in the test method
        List<PolicyDetail> policyDetails = getPolicyDetails(name, effdate, companyName);


}

   public List<policyDetail> getPolicyDetails(String name, Date effDate, String companyName) {

}


}

Wrong test coverage in golang or what is the meaning of covered and tracked

I must be very dump, but I can't see my error. I've started a small golang application to test it out and learn some go. In my main package I have a main.go with for example a function called NewApp.

In my test file I've called it several times, but in the coverage its first line is marked as "not tracked". This function returns an App struct, but the whole struct definition is marked as "not tracked" to.

On the other hand I can't understand the difference between "not covered" and "not tracked". And is there a way to test the main function? I can't see the advantage of that.

My code is here: http://ift.tt/2d1yvDx

Thanks in advance

Test Account for Android Emulator

I've an Android application with Google login, to test this application and do login, in a Virtual Device Emulator, i've added a personal account in that Emulator.

Question is: Can i add a test account instead of my personal? (but i have to create that, and in creation process Google ask me my personal phone number...)

Do you usually create another account or you use your personal?

Ember integration test setup() not being called

I'm trying to follow these instructions to initialize a service in an Ember component integration test. However, it appears that setup() is never called and the tests fail. However, I can add that same code to the beforeEach() function and I can see that it was called and the tests pass.

moduleForComponent('header-editor', 'Integration | Component | header editor', {
  integration: true,
  setup () {
    // manually invoke the ember-intl initializer
    instanceInitializer.initialize(this);
    let intl = this.container.lookup('service:intl');
    // this log statement will NOT appear in the console
    console.log('setup', intl);
    intl.setLocale('en-us');
  },
  beforeEach () {
    // // manually invoke the ember-intl initializer
    instanceInitializer.initialize(this);
    let intl = this.container.lookup('service:intl');
    // this log statement appears in the console
    console.log('beforeEach', intl);
    intl.setLocale('en-us');
  }
});

Does anyone know why setup() would not be called?

How to make an assert for required field messages?

How do I make an assert for this required field message?

I don't think css selectors will work on this, because this message comes from the browser itself, isn't it? Is there a way to do it?

Java Spring Boot Test: How to exclude java configuration class from test context

I have a java web app with spring boot

When run test I need to exclude some java config files:

Test config (need to include when test run):

@TestConfiguration
@PropertySource("classpath:otp-test.properties")
public class TestOTPConfig {
}

Production config (need to exclude when test run):

 @Configuration
 @PropertySource("classpath:otp.properties")
 public class OTPConfig {
 }

Test class (with explicit config class):

@RunWith(SpringRunner.class)
@SpringBootTest(classes = TestAMCApplicationConfig.class)
public class AuthUserServiceTest {
  ....
}

Test config:

@TestConfiguration
@Import({ TestDataSourceConfig.class, TestMailConfiguration.class, TestOTPConfig.class })
@TestPropertySource("classpath:amc-test.properties")
public class TestAMCApplicationConfig extends AMCApplicationConfig {
}

Also have class:

@SpringBootApplication
public class AMCApplication {
}

When test is running OTPConfig used, but I need TestOTPConfig...

How can I do it?

Setting up a QA Environment for Web and Desktop Application Testing - Finance

Hoping you can help or direct me. Previously had a role overlooking a small test team and working on Manual tests with an environment that was already set up and didn't need to delve so much into how it worked. New role now, but I'm looking to set up a nice clean Test environment.

I understand a 'dummy' replica of what's out there already, it's just the logistics of going about it that I'm unsure of.

Some details:

I work for a company that works with payments, and they have both Desktop and Web applications. Front end applications (customer facing) are all web apps, and will need to be regression tested. Then there are web apps and desktop apps that handle the backend data, with the desktop apps being mostly tasks.

I'm wondering if I need to get the company to buy some more hardware, or whether I can pinch space on the already existing hardware to duplicate the environment. Looking to purchase or acquire some Testing and Test Management software in order to keep tests in check, but that's relatively simple.

Languages that the applications were written in are varied as well, PHP, java, VB6, etc.

Any help offered would be brilliant, and if you need more information then please ask away as I realise it's a bit vague. As it's my first time doing this I'm not 100% aware of what specifics I would need to mention.

Thanks.

differences between online responsive test

I am testing the responsivity of the design my site. But for the same device (for example Iphone 5) I get different answers depending on the 'responsivetest'site . Does someone saw that before? Thank you.

enter image description here

How to test with Espresso a PendingIntent generated by TaskStackBuilder

I am developing some cool Push Notification in our app and making some test to cover that when the user clicks on one of the notification then the app launch the correct intent to open the correct Activity.

In our aplication we have a StartupActivity that captures all this push notifications and route to the correct screen with the correct extras. The UI test, done with Espresso, that cover the correct launch looks like this:

    @Test @Ignore
    public void showsANotificationAndOpensTheCorrectScreen() throws
            UiObjectNotFoundException {
        sendBroadcast(PushNotificationBuilder
                .withAction("com.xxxx.android.gcm.SOMETHING")
                .withType("SOME_TYPE")
                .withRelatedId(ANY_ID)
                .withTitle(ANY_TITLE)
                .build());

        tapNotificationWithTitle(ANY_TITLE);

        intended(allOf(
                hasComponent(DesitinyActivity.class.getCanonicalName()),
                hasExtra("extra_id", Long.valueOf(ANY_ID)),
                hasExtra("extra_other_extra", true)));
    }

As you can see, this test simulates receive a notification, tap on it and checks if the Intent to the correct Activity is thrown.

The problem arrives when we have a screen that is not on the first level, for example the typical Detail Screen, and we need to build a stack of activities. For that we use TaskStackBuilderto generate a PendingIntent with all the stack of intents. An example code that generates the stack given a final Activity's intent:

private PendingIntent generateexampleTaskBuilder(Context context, Intent intentToTheFinalScreen) {
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        stackBuilder.addNextIntent(ExampleActivity.getLaunchIntent(someExtra, context));
        stackBuilder.addNextIntent(intent);
        return stackBuilder.getPendingIntent(PushIdIntegerGenerator.getUniquePushId(),
                PendingIntent.FLAG_UPDATE_CURRENT);
    }

The problem is that the intended never verifies this Pending Intent and the test never pass. If I changed the pending intent for a normal and direct Intent the test passes but the method intended() can not captures the pending intents.

Is there any form to test the pending intents?

smallcheck what does "but n did not meet ==>" and how do I know which

I wrote this property

prop_lookupsymbol = forAll $ \name table scope -> case lookupsymbol name table scope of
                                                  Just (s,_) -> property $ is_parent s scope
                                                  Nothing ->  forAll $ \s->is_parent s ==> (lookupsymbol name table s) == Nothing

and ran it with smallCheck 3 prop_lookupsymbol, the results are :

Completed 9000 tests without failure.
But 9000 did not meet ==> condition.

I know it refers to ==> call in the property but what does it mean by did not meet ? Should I worry about this ? and if yes then how do I get the tests that didn't meet the condition ?

run two tests with Gradle through the command line

How do I run two or more, not all, tests in Gradle through the command line?

I know that I can run a single test with --test MyTestClassName.

Kind of --test TestA,TestB looks to work, but it doesn't: No tests found for given includes: [TestA,TestB]

Is it even possible? I mean, my IDE is able to, but I don't know how.

What the best way for naming TestMethod

what is the best way to give a name to a method of testing or how to name (the best way) a TestMethod ?

thank you

Ember.js acceptance test check inputs' values

I have a lot of logic in a big form, where input values depend on each other. I am trying to test values of these inputs.

In this case find("#sales_price").val() results in empty string:

fillIn("#sales_price", 12345);
andThen(function() {
  assert.equal(find("#sales_price").val(),123456);
...

In such example binding stops to work and find("#sales_price").val() gets initial value of input (but not 12345):

find("#sales_price").val(12345);
andThen(function() {
  assert.equal(find("#sales_price").val(),123456);
...

How do I make IntelliJ IDEA run all the tests including sub packages

If I click on a package and do control-shift-F10, it failed with this error:

Error running ScalaTests in 'tests': Not found suite class.

And when open test configuration i see the the "Test Package" is

src.main.scala.com.myproject.pro.integration.tests

And when i change it to be:

com.myproject.pro.integration.tests

it just run the tests that existing in the first level without running the sub packages tests.

my configuration:

enter image description here

How to protect enum assignment

I want to prevent invalid value enum assigment. I know if i even assign value that is not in enum it will work. Example:

enum example_enum
{
    ENUM_VAL0,
    ENUM_VAL1,
    ENUM_VAL2,
    ENUM_VAL3
};

void example_function(void)
{
  enum example_enum the_enum = ENUM_VAL3; // correct
  the_enum = 12345; // will work
  bar(the_enum); // this function assumes that input parameter is correct
}

Is there easy, efficient way to check if assignment to enum is correct? I could test value by function

void foo(enum example_enum the_enum)
{
  if (!is_enum(the_enum))
    return;

  // do something with valid enum
}

I could resolve this in following way:

static int e_values[] = { ENUM_VAL0, ENUM_VAL1, ENUM_VAL2, ENUM_VAL3 };
int is_enum(int input)
{
  for (int i=0;i<4;i++)
    if (e_values[i] == input)
      return 1;
  return 0;
}

For me, my solution is inefficient, how can i write this if i have more enums and more values in enums?

Integration tests in golang - how to test the link between the router and the http.Handlers?

I've been tinkering around with golang and I try to implement a little todo application which should grow with the time. My thoughts about the applications architecture are the following:

  • The main package sets up the server and integrates the "services/handler" of the other packages in it's router under the corresponding path prefixes.
  • Every "service" has its own handlers and routes them correctly

So I've started just with the main package and wrote some todo handlers. To test the API I've written some integration tests (request/response). Now, I've removed the todo logic from the main package into it's own. When I execute go test -cover it shows me just the coverage of the main.go, but not for the todo package. That leads me to the conclusion that each package has to test on it's own.

So I have not to test the API in the main package but the integration, that '/todos' ends up in the todo package and nothing more, is that right? How can I test that? And in the todo package I have to test:

  • The routing in the package
  • And with a response recorder the API implementation

Is that right too? So how can I test the routing on it's own? Is that possible?

Here is my git repository: http://ift.tt/2dcQdUr

Thanks in advance

Testing of mandate elements with testing tool

I want to test whether necessary elements like (AP, TKOK, RFD) are present in the PNR or not. Can I test it with some testing tool? Please advise.

Mocking functions in Golang to test my http routes

I'm totally confused figuring out how I can mock a function, without using any additional packages like golang/mock. I'm just trying to learn how to do so but can't find many decent online resources.

Essentially, I followed this excellent article that explains how to use an interface to mock things.

As so, I've re-written the function I wanted to test. The function just inserts some data into datastore. My tests for that are ok - I can mock the function directly.

The issue I'm having is mocking it 'within' an http route I'm trying to test. Am using the Gin framework.

My router (simplified) looks like this:

func SetupRouter() *gin.Engine {

    r := gin.Default()
    r.Use(gin.Logger())
    r.Use(gin.Recovery())

    v1 := r.Group("v1")
    v1.PATCH("operations/:id", controllers.UpdateOperation)
}

Which calls the UpdateOperation function:

func UpdateOperation(c *gin.Context) {
    id := c.Param("id")
    r := m.Response{}

    str := m.OperationInfoer{}
    err := m.FindAndCompleteOperation(str, id, r.Report)

    if err == nil {
      c.JSON(200, gin.H{
          "message": "Operation completed",
      })
    }
}

So, I need to mock the FindAndCompleteOperation() function.

The main (simplified) functions looks like this:

func (oi OperationInfoer) FindAndCompleteOp(id string, report Report) error {
    ctx := context.Background()
    q := datastore.NewQuery("Operation").
        Filter("Unique_Id =", id).
        Limit(1)

    var ops []Operation

    if ts, err := db.Datastore.GetAll(ctx, q, &ops); err == nil {
        {
            if len(ops) > 0 {
                ops[0].Id = ts[0].ID()
                ops[0].Complete = true

                // Do stuff

                _, err := db.Datastore.Put(ctx, key, &o)
                if err == nil {
                  log.Print("OPERATION COMPLETED")
                }
            }
        }
    }

    err := errors.New("Not found")
    return err
}

func FindAndCompleteOperation(ri OperationInfoer, id string, report Report) error {
    return ri.FindAndCompleteOp(id, report)
}

type OperationInfoer struct{}

To test the route that updates the operation, I have something like so:

FIt("Return 200, updates operation", func() {
    testRouter := SetupRouter()

    param := make(url.Values)
    param["access_token"] = []string{public_token}

    report := m.Report{}
    report.Success = true
    report.Output = "my output"

    jsonStr, _ := json.Marshal(report)
    req, _ := http.NewRequest("PATCH", "/v1/operations/123?"+param.Encode(), bytes.NewBuffer(jsonStr))

    resp := httptest.NewRecorder()
    testRouter.ServeHTTP(resp, req)

    Expect(resp.Code).To(Equal(200))

    o := FakeResponse{}
    json.NewDecoder(resp.Body).Decode(&o)
    Expect(o.Message).To(Equal("Operation completed"))
})

Originally, I tried to cheat a bit and just tried something like this:

m.FindAndCompleteOperation = func(string, m.Report) error {
  return nil
}

But that affects all the other tests etc.

I'm hoping someone can explain simply what the best way to mock the FindAndCompleteOperation function so I can test the routes, without relying on datastore etc.

How to test Service Contracts implemented as OSGi Bundles?

We are in the process of transitioning towards SOA.

Our current goal is to try and ensure that more of the application is developed as "Services" (mainly to improve visibility of capability, re-use and de-risk change). Some of those services will be exposed as web services, but many (and probably the majority) will not, and be used for "internal" use only to help reap some of the benefits of SOA.

For those "internal" services we are currently intending on implementing them as OSGi bundles; however we are struggling to understand how best to test them. Our goal is to enable the current System Test team to test all types of services and we have been investigating tools like SoapUI and SOA Test; however it's becoming clearer that we may face some challenges in testing our services implemented as OSGi bundles using tools like these; and indeed asking the test team to do so.

So we're looking for some advice on how best to test aspects of our capability designed to act as a "service", but implemented as an OSGi bundle instead of a web service.

What tools would people recommend, and is this a type of testing that's traditionally done by a developer during unit test, or can it be done by a less technical tester, undertaking the same basic principles of testing interfaces (i.e. inputs, processing, outputs)?

Geb: Open new tab for each test

I am trying to open new tab for each iteration of the test for each set of data in the where block.

I ma trying like:

setup:
Keys.chord(Keys.CONTROL, "t")

but it does not work.

How to do it?

Angular 2: Testing [(ngModel)] two way data binding

I am trying to test the two way data binding of ngModel with the following code, but when I am running my test I always get: Expected '' to be 'test@wikitude.com', 'searchQuery property changes after text input'. Maybe it has something to do with the searchField.dispatchEvent part, but so far I couldn't figure out why the test is not changing the textContent of my displayField. The project was built with angular-cli": "1.0.0-beta.15. I tried to follow this guide but so far had no luck. Would be nice if you could help me make my test pass.

This is my component:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-search',
  templateUrl: './search.component.html',
  styleUrls: ['./search.component.css']
})
export class SearchComponent implements OnInit {
  searchQuery: string;
  active: boolean = false;

  onSubmit(): void {
    this.active = true;
  }
}

This is my component template:

<input id="name" [(ngModel)]="searchQuery" placeholder="customer">
<h2><span></span></h2>

And here are is my spec:

/* tslint:disable:no-unused-variable */

import {TestBed, async, ComponentFixture, tick} from '@angular/core/testing';
import { SearchComponent } from './search.component';
import {CommonModule} from "@angular/common";
import {FormsModule} from "@angular/forms";
import {By} from "@angular/platform-browser";

describe('Component: SearchComponent', () => {
  let component: SearchComponent;
  let fixture: ComponentFixture<SearchComponent>;

  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [SearchComponent],
      imports: [
        CommonModule,
        FormsModule
      ]
    });

    fixture = TestBed.createComponent(SearchComponent);
    component = fixture.componentInstance;
  });

  it('should bind the search input to the searchQuery variable', () => {   
    const searchInputText: string = 'test@wikitude.com';
    const searchField: HTMLInputElement = fixture.debugElement.query(By.css('input')).nativeElement;
    const displayField: HTMLElement = fixture.debugElement.query(By.css('span')).nativeElement;

    searchField.value = searchInputText;

    searchField.dispatchEvent(new Event('input'));

    fixture.detectChanges();

    expect(displayField.textContent).toBe(searchInputText, 'searchQuery property changes after text input');
  });
});

How can I test a React Native component behaviour and props using Jest?

I have successfully set up the Jest test environment in a React Native component that draws a Button (basically a combination of Touchable and Text components).

I can run snapshot tests like the following:

test('Renders', () => {
  const component = renderer.create(
    <Button>
      Button
    </Button>
  )
  const tree = component.toJSON()
  expect(tree).toMatchSnapshot()
})

However, I want to make a step further and start testing the props of the component (i.e., checking that the Button text is passed as props.children and I also want to test the onPress functionality, simulating the user tap and checking that a passed function is called.

How can I do this with a Jest + React Native environment?

PS: I'm currently running this code with react-native ~> v0.34, jest ~> v15.1.1 and jest-react-native ~> v15.0.0.

lundi 26 septembre 2016

Using nightwatch elementIdText value

So I have a div that contains some text followed by a link. Im using nightwatch to write some tests. How do I use the result of

browser
  .elementIdText('elementId')
  .url("how do I use the url from elementIdText ?!")

How to create / Write STDF file with python?

I'm Trying to convert .txt data file to STDF file.

Is there any way to do that? Are there any libraries in Python which would help in cases like this?

Thanks!

TypeError: Cannot read property 'injector' of null after upgrading to Angular 2.0 final

After upgrading from Angular 2 RC5 to 2.0 Final, I'm seeing the following errors when running my tests. I'm not sure what the problem is.

TypeError: Cannot read property 'injector' of null
    at TestBed._createCompilerAndModule (webpack:///Users/mraible/dev/ng2-demo/~/@angular/core/testing/test_bed.js:247:0 <- src/test.ts:20777:44)
    at TestBed._initIfNeeded (webpack:///Users/mraible/dev/ng2-demo/~/@angular/core/testing/test_bed.js:213:0 <- src/test.ts:20743:39)
    at TestBed.createComponent (webpack:///Users/mraible/dev/ng2-demo/~/@angular/core/testing/test_bed.js:297:0 <- src/test.ts:20827:14)

Here's an example of one of my tests:

import { MockSearchService } from '../shared/search/mocks/search.service';
import { EditComponent } from './edit.component';
import { TestBed } from '@angular/core/testing/test_bed';
import { SearchService } from '../shared/search/search.service';
import { MockRouter, MockActivatedRoute } from '../shared/search/mocks/routes';
import { ActivatedRoute, Router } from '@angular/router';
import { FormsModule } from '@angular/forms';

describe('Component: Edit', () => {
  let mockSearchService: MockSearchService;
  let mockActivatedRoute: MockActivatedRoute;
  let mockRouter: MockRouter;

  beforeEach(() => {
    mockSearchService = new MockSearchService();
    mockActivatedRoute = new MockActivatedRoute({'id': 1});
    mockRouter = new MockRouter();

    TestBed.configureTestingModule({
      declarations: [EditComponent],
      providers: [
        {provide: SearchService, useValue: mockSearchService},
        {provide: ActivatedRoute, useValue: mockActivatedRoute},
        {provide: Router, useValue: mockRouter}
      ],
      imports: [FormsModule]
    });
  });

  it('should fetch a single record', () => {
    const fixture = TestBed.createComponent(EditComponent);

    let person = {name: 'Emmanuel Sanders', address: {city: 'Denver'}};
    mockSearchService.setResponse(person);

    fixture.detectChanges();
    // verify service was called
    expect(mockSearchService.getByIdSpy).toHaveBeenCalledWith(1);

    // verify data was set on component when initialized
    let editComponent = fixture.debugElement.componentInstance;
    expect(editComponent.editAddress.city).toBe('Denver');

    // verify HTML renders as expected
    let compiled = fixture.debugElement.nativeElement;
    expect(compiled.querySelector('h3').innerHTML).toBe('Emmanuel Sanders');
  });
});

For a pull request that demonstrates this issue, please see GitHub: http://ift.tt/2dfQszJ