I know how to write "Parameterized tests" in Java and Data Driven tests in Groovy using Spock framework. But how to write in JavaScript? Now I try to show how to make it working using mocha framework.
Data Driven tests in Mocha is called "Dynamically generated tests", based on the API documentation, there are 2 steps:
1) Create a test data array;
2) Iterate the test data, generate the test case dynamically, the test case name in "it" block is also generated dynamically, which is quite similar with Spock framework.
The implementation is pretty straight forward. Here is the example of my implementation in the Tennis Game Kata:
https://github.com/stevez/TennisGame-solution/blob/master/javascript/test/Tennis-test.js
The javascript example project is here:
https://github.com/stevez/TennisGame-solution/tree/master/javascript
Next step I will look at how to work it using Jasmine framework.
Showing posts with label TDD. Show all posts
Showing posts with label TDD. Show all posts
Thursday, June 9, 2016
Friday, June 3, 2016
Debug Mocha tests using Visual Studio Code IDE
It is amazing that we could easily debug Mocha javascript test code in Visual studio Code IDE.
Here is the launch.json file:
Click the Debug button, press F5, then you will see the debugger running.
The detail file is also in github:
https://github.com/stevez/kata-Yatzy-solution/blob/master/javascript/.vscode/launch.json
You can check my sample code in github for details:
https://github.com/stevez/kata-Yatzy-solution/tree/master/javascript
Here is the launch.json file:
Click the Debug button, press F5, then you will see the debugger running.
The detail file is also in github:
https://github.com/stevez/kata-Yatzy-solution/blob/master/javascript/.vscode/launch.json
You can check my sample code in github for details:
https://github.com/stevez/kata-Yatzy-solution/tree/master/javascript
Wednesday, May 6, 2015
How to mock a for loop using mockito
Today when I tried to use mockito to write unit test cases, I found I need to mock the for loop operation. Then I found the solution from here in stackoverflow: the basic idea is to mock the iterator class and collection class, and base on your situation, you need to set the expectation of iterator.hasNext() and iterator.next() method.
The following code is copied from the above link:
The following code is copied from the above link:
Monday, April 27, 2015
What I learned from Agile Engineering training
Last week I took the 3-day "Agile Engineering Training" in TELUS, thanks a lot to our trainers from LeanIntuIt - Shawn Button and Declan Whelan. I learned a lot from them. The course covers TDD, Simple Design, SOLID principles, refactoring and dealing with legacy code. The fun part is there are a lots of coding Kata, like Bowling Game, Gilded Rose, etc. I am so glad to have an opportunity to learn those stuff, even actually I learned them since 10 years ago, this time I feel this training is a kind of a review of what I learned since I decided to be a software craftsman.
Here is the mind map summarized of what I learned.
Add some thoughts:
Resources:
Here is the mind map summarized of what I learned.
Add some thoughts:
- TDD/SOLID principles/Refactoring skills become more critical and in an Agile/Scrum team, you have to be great, to be better so that you can deliver faster, your code will be easier to change, easier to maintain;
- Simple Design - it is summarized by only 2 points: fixing names and removing duplication. Combining with TDD's Red/Green/Refactoring cycle, it means just repeating this 2 things with test cases, your complex code logic design phase will turn into many tiny steps which just renaming and removing duplication; if you can do it fluently, the effort of thinking hard before hand becomes simple physical typing movements - which means you can design the code without thinking too much. This conclusion is so striking.
- Refactoring - When I tried the Kata Gilded Rose (a simpler version which have all the tests before), I really sense the power of simple design - refactoring by doing renaming and extract methods, then the business logic gradually emerged, and design pattern is emerged. For me it means as long as you have all the test cases, then you can refactoring the code without need to understand the business logic, and business logic will be more clear after you refactored. That is another aha moment for me. Looks like code quality is a separate attribute beside the domain knowledge. If we apply this to code review, it means the good code should be enough understandable without understanding the business background first.
Resources:
- Four Elements of Simple Design, by JBrain
- Kata: Gilded Rose, this is a great Kata about refactoring, it worth trying more times
Saturday, March 10, 2012
Presentation note - Continuous Integration in the Mobile World
Yesterday I watched the presentation Continuous Integration in the Mobile World by Godfrey Nolan in InfoQ. It is a very informative, the author covers the Jenkins CI server, Version Control and test tools for ios and Android mobile platform, and the author tells us how he integrates those tools in his company's mobile application development. Most of those tools he mentioned are first time for me. We use Jenkins, but I haven't realize that there are so many good tools available for you.
Here I just summarize the tools which are mentioned in the presentation.
Jenkins Plugins
- Android Emulator Plugin
- Xcode Plugin
Test tools
- Perfecto mobile, test real mobile device via the cloud, I feel it is quite similar with DeviceAnyWhere.
- TestFligh App, ios beta test on the fly.
- FoneMonkey, Functional test tool for ios and Android
- Robotium, like Selenium, it is for Android UI test framework
- OCUnit, Objective C unit test framework
- OCUnit2junit, a ruby script to convert OCUnit to Junit, which allows Jenkins to run the OCUnit.
I need to do more research on those tools, I really appreciate Godfrey provide such a informative and inspiring presentation.
Here I just summarize the tools which are mentioned in the presentation.
Jenkins Plugins
- Android Emulator Plugin
- Xcode Plugin
Test tools
- Perfecto mobile, test real mobile device via the cloud, I feel it is quite similar with DeviceAnyWhere.
- TestFligh App, ios beta test on the fly.
- FoneMonkey, Functional test tool for ios and Android
- Robotium, like Selenium, it is for Android UI test framework
- OCUnit, Objective C unit test framework
- OCUnit2junit, a ruby script to convert OCUnit to Junit, which allows Jenkins to run the OCUnit.
I need to do more research on those tools, I really appreciate Godfrey provide such a informative and inspiring presentation.
Subscribe to:
Posts (Atom)