facundocabrera / generator-tamagotchi

Yeoman Generator for fun & profit - Deprecated
2 stars 1 forks source link

Create a test suite for the generator #3

Closed facundocabrera closed 11 years ago

jgauna commented 11 years ago

Test suite quick start (?

Added a new branch called tests-unit for developing a test suite for this brand new generator.

Inside the cloned folder should run:

It will create a new test folder and inside of it the structure:

Now should be able to write some tests using Mocha:

http://visionmedia.github.io/mocha

e.g:

var assert = require("assert")
describe('Module test name', function(){
  describe('#indexOf()', function(){
    it('should return -1 when the value is not present', function(){
      assert.equal(-1, [1,2,3].indexOf(5));
      assert.equal(-1, [1,2,3].indexOf(0));
    })
  })
})

Assertions

npm install sinon-chai

Usage:

http://chaijs.com/plugins/sinon-chai

Let me know what you think.

facundocabrera commented 11 years ago

Cool!

Now, we will need to try something extra:

  1. We will use probably Jasmine or QUnit. Do we have something for those???
  2. Is it posible to add Karma alias Testacular as well ?
jgauna commented 11 years ago

Regarding Jasmine/qUnit, I think it's sounds like a lot. Chai extended with sinon features should be enough for asserts, isn't it?

On the other hand, Testacular seems great to add some real cross browser testing.

Resume.

If it's ok with you, I will update the tests-suite's branch home page with the docs.

facundocabrera commented 11 years ago

Because the evaluation we did in #2 we have some facts:

  1. Jasmine as BDD.
  2. A cool process for translate .story files to code ('jasmine skeleton').
  3. Eventually use phantomjs/nodejs/something as environment for the run the test suite.

Maybe the generator's test suite could be a good example for a future generalization of the testing process.

What do you think?

jgauna commented 11 years ago

Final test suite's architecture

After evaluating for a while, we want to create a brand new generator (new repository maybe).

It will handle the creation of tests. We think it's better because we will have everything in just one piece that could be use to test any generator and every project. Just install inside your project and use it!


Usage

' yo dt-pcg

- It will look for all .story files and matching them with the new .js files creating the basic Jasmine skeleton.

    We propose this skeleton (Please validate it)

    describe("Scenario <NAME>", function() {
        it("GVIEN ...", function() {

            // Write test here
        });

        it("WHEN ...", function() {

            // Write test here
        });

        it("THEN ...", function() {

            // Write test here
        });

        it("AND ...", function() {

    - It's important to clarify that this will build the tests and check for your generator's file structure every time it runs.

        - Note: If the .js files were modified and you re-run the generator, it will run just the tests. It's intelligent!

Commands

Black magic, rabbits and witches

We could provide an API for everybody who wants to write his own method for testing theirs generators. Every time you run yo dt-pcg you will be running that brand new method if needed.

Resume/Extras

facundocabrera commented 11 years ago

Just go ahead and let see what you can get :smile:

jgauna commented 11 years ago

Vamos a tener una carpeta live, donde van a estar los .story del SMOKE TEST y la carpeta automation donde van a estar los .js. Todo esto lo automatizamos con grunt y la idea es generar los .js (tests) con un comando de grunt. Aca va una exlicacion, que les parece?

Scenario: We need to see a text that confirms that the user was valid

Given a When I type a in a Then I will see a in a And I will wait for

Examples page_url|user_name|text_area|text_information|label_area|time http://www.test-url.com|test-user|#text-area-id|the user is valid|#label-id-test|2000

De aca sacamos que podemos usar

exports.tests = [{

name: "checks if title contains the search query",
func: function(done) {

var page_url = 'http://www.test-url.com',
    user_name = 'test-user',
    text_area = '#text-area-id',
    text_information = 'the user is valid',
    label_area = '#label-id-test';

    exports.driver
        .click('#js-command-bar-field')
        .setValue('#js-command-bar-field',query)
        .submitForm('.command-bar-form')
        .getTitle(function(title) {
            buster.assertions.assert(title.indexOf(query) !== -1);
        })
        .end(done);

}}

];