Created
June 13, 2013 12:31
-
-
Save shinofara/5773314 to your computer and use it in GitHub Desktop.
【javascriptを使う人に知って貰いたい(エンジニア、デザイナ問わず)】karmaを使ったテスト駆動開発入門(ついでにJasmineも) ref: http://qiita.com/shinofara/items/b3677ffdfc0c7e45e8d4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir -p karma/spec | |
$ mkdir -p karma/src | |
$ cd karma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm install -g karma |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INFO [watcher]: Changed file "/work/karma/spec/HelloSpec.js". | |
Chrome 27.0 (Mac): Executed 1 of 1 SUCCESS (0.293 secs / 0.011 secs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ karma init | |
Which testing framework do you want to use ? | |
Press tab to list possible options. Enter to move to the next question. | |
> jasmine | |
Do you want to use Require.js ? | |
This will add Require.js adapter into files. | |
Press tab to list possible options. Enter to move to the next question. | |
> no | |
Do you want to capture a browser automatically ? | |
Press tab to list possible options. Enter empty string to move to the next question. | |
> Chrome | |
> | |
Which files do you want to test ? | |
You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js". | |
Enter empty string to move to the next question. | |
> | |
Any files you want to exclude ? | |
You can use glob patterns, eg. "**/*.swp". | |
Enter empty string to move to the next question. | |
> | |
Do you want Testacular to watch all the files and run the tests on change ? | |
Press tab to list possible options. | |
> yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vim karma.conf.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ vim spec/HelloSpec.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ karma start karma.conf.js | |
INFO [karma]: Karma server started at http://localhost:9876/ | |
INFO [launcher]: Starting browser Chrome | |
INFO [Chrome 27.0 (Mac)]: Connected on socket id FqwLPzInsYRW6baEegdg | |
Chrome 27.0 (Mac) Hello Test test FAILED | |
Expected 'test1' to equal 'test'. | |
Error: Expected 'test1' to equal 'test'. | |
at null.<anonymous> (work/karma/spec/HelloSpec.js:9:15) | |
Chrome 27.0 (Mac): Executed 1 of 1 (1 FAILED) (0.107 secs / 0.02 secs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cd work/karma | |
$ karma start karma.conf.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ karma start karma.conf.js | |
INFO [karma]: Karma server started at http://localhost:9876/ | |
INFO [launcher]: Starting browser Chrome | |
INFO [Chrome 27.0 (Mac)]: Connected on socket id FqwLPzInsYRW6baEegdg | |
Chrome 27.0 (Mac) Hello Test test FAILED | |
Expected 'test1' to equal 'test'. | |
Error: Expected 'test1' to equal 'test'. | |
at null.<anonymous> (work/karma/spec/HelloSpec.js:9:15) | |
Chrome 27.0 (Mac): Executed 1 of 1 (1 FAILED) (0.107 secs / 0.02 secs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* http://pivotal.github.io/jasmine/ | |
*/ | |
describe("Hello Test", function() { | |
it("test", function() { | |
var a = 'test';//actual テストする値 | |
var e = 'test';//expect 期待値 | |
expect(a).toEqual(e); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files: [ | |
'spec/*.js' | |
], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment