- As a
- software developer
- I want to
- write good unit tests for my code
- But
- it is time consuming and boring, so I end up postponing it.
- TestPilot helps by
- suggesting readable unit tests based on my code and documentation
- Unlike
- other test generators that focus on coverage and produce tests that are hard to understand.
Want to write good unit tests for your code but it just takes too much time, or add tests to a legacy code base but don’t know where to start? Let TestPilot suggest unit tests based on your existing source code and documentation!
What can TestPilot do?
Leveraging the cutting-edge machine-learning models powering GitHub Copilot, TestPilot creates readable unit tests with meaningful assertions for your JavaScript/TypeScript code.
When you point it at a function in a code repo, TestPilot will scan the repo for relevant doc comments and code examples, and then generate a unit test for the function based on the information it finds. You can run the test straight away, and if it doesn't pass you can feed back any errors you are seeing to TestPilot and interactively refine the generated test until it's just right.
For example, consider the method
Deque.prototype.clear
from the js-sdsl
package. The package
documentation contains the following code example for this method:
const v = new Vector([1, 2, 3])
v.clear()
console.log(v.size()) // 0
console.log(v.empty()) // true
From this example, TestPilot constructs the following test:
const assert = require('chai').assert
const js_sdsl = require('js-sdsl')
describe('test js_sdsl', function () {
it('test js_sdsl.Deque.prototype.clear', function () {
let v = new js_sdsl.Deque([1, 2, 3])
v.clear()
assert.equal(v.size(), 0)
assert.equal(v.empty(), true)
})
})
Does it work in practice?
We have taken TestPilot through its paces on a number of popular (and not so popular) npm packages and measured statement coverage of the generated tests, and found that it often achieves 60-80% coverage. Here are some examples:
Package | Statement coverage |
---|---|
bluebird | 68.2% |
image-downloader | 75.8% |
js-sdsl | 36.5% |
simple-statistics | 80.1% |
zip-a-folder | 88.0% |
A detailed write-up is available on arXiv.
How can I try it out?
TestPilot has been open-sourced under the MIT license and is available at https://github.com/githubnext/testpilot.