normal tests, written after the development, have mainly one purpose
regression tests relief you code by a task: to be similar to itself
thus, they enable the code to evolve, without too many worries
but tests are terribly boring
the typical test is just "stating the obvious"
and you will never find the time for them
increase the test coverage? get more people to do that manuallyi hate boring things
and we where quite stressed, in the frontend
but from May to now, i was able to keep developing and at the same time writing ~200 test specifications
and they really helped me
how to do that?
everything is based on an extremely simple principle
your tests will tell you when you're done
in a very zen way, your end will meet your principle :D
also several test / dev cycles could happen, just keep in mind to revert the traditional order
every discovered bug, should be handled as a new feature
bug -> fix -- no
bug -> test -> fix -- yes
that's the only way to slowly eliminate regression problems
as we said, the principle is simple:
so, the first thing we get, are tests
"what do i want"? first of all
describe('my component', function() { it('goes to detail after click on the item', function() { spyOn(history.newPage); this.component.select('$item').eq(0).click(); expect(history.newPage) .toHaveBeenCalledWith({ page: 'detail', item: 3243 }); }); });
this is the only way i know in order to think outside-in, from the very beginning
this process can lead you to always better interfaces, or not
(that means, to better testing logic instead)
expect(node.visible).toBe(true); expect(node).toBeVisible();
final consideration, for those with an analytical mind
it's not bullet-proof
but it helps, a lot
for the lazy:
expect('')
let the tests write themselves
advantage? regression
it('shows the correct value', function() { var $value = this.component.select('$value'); expect(raw in this.component.data).toBe(true); expect(this.component.lastTemplateInput.raw) .toBe(0.3476); expect(this.component.format(0.3476)) .toBe('34.76%'); expect(this.component.lastTemplateInput.formatted) .toBe('34.76%'); expect($value.length).toBe(1); expect($value.text()).toBe('34.67%'); });
yes, tests are supposed to grow, while code is supposed to shrink
at some extent
tackle the same problem
from different angles
from my experience, in order to switch from a normal trial and error process to a test driven one, an initial development effort is needed.
this effort is usually quite small , requiring one or two days. still you may feel quite unconfortable with your initial testing tools. convenience will come with time
if you don't have questions, why aren't you yet developing with test driven?