TDD & Jetstar
With Matty & Juan
TDD & Jetstar
- TDD FAQ
- How we TDD on JQ
- TDD No-no's
What is TDD?
- A Methodology framework
- AAA: Arrange, Act, Assert
- "Test until fear leads to boredom" - Kent Beck
What should you test?
- Start with requirements in Jira tickets
- Test your expected and unexpected scenarios
- Add tests as bugs come back from QA
What should you test?
- Start with requirements in Jira tickets
- Test your expected failures as well
- Add tests as bugs come back from QA
What should you test?
- Start with requirements in Jira tickets
- Test your expected and unexpected scenarios
- Add tests as bugs come back from QA
What AAA looks like
AAA: Arrange a test
- Mock base model with "real" data from your API
- Define your own data (if you're starting from scratch)
describe('Given check-in flow', function () {
it('should list the checked-in segments', function() {
var firstFlightOnly = [];
var lastFlightAfterFirst = [];
var arrangeFirstFlight = _.cloneDeep(segments);
var arrangeLastFlight = _.cloneDeep(segments);
// set last flight not available for check-in
arrangeFirstFlight[1].IsSegmentCheckInAvailable = false;
arrangeFirstFlight[1].PaxSegments[0].HasCheckedIn = false;
arrangeFirstFlight[1].PaxSegments[1].HasCheckedIn = false;
arrangeFirstFlight[1].PaxSegments[2].HasCheckedIn = false;
// set first flight to already checked-in
arrangeLastFlight[0].IsSegmentCheckInAvailable = false;
arrangeLastFlight[0].PaxSegments[0].HasCheckedIn = true;
arrangeLastFlight[0].PaxSegments[1].HasCheckedIn = true;
arrangeLastFlight[0].PaxSegments[2].HasCheckedIn = true;
// set some people checked-in on last flight
arrangeLastFlight[1].IsSegmentCheckInAvailable = true;
arrangeLastFlight[1].PaxSegments[0].HasCheckedIn = true;
arrangeLastFlight[1].PaxSegments[1].HasCheckedIn = true;
arrangeLastFlight[1].PaxSegments[2].HasCheckedIn = false;
});
});
AAA: Act on test data
- Tweak your base data to simulate a scenario
- Fake anything that fails (it's just a test)
describe('Given check-in flow', function () {
it('should list the checked-in segments', function() {
// ... already arranged data...
// act on the data so a new model is made
_.each(arrangeFirstFlight, function(segment){
firstFlightOnly.push(new SegmentModelWithPaxInfo(
segment,
mockBoarding.booking.Passengers
));
});
// act on the data so another model is made, different to the last
_.each(arrangeLastFlight, function(segment){
lastFlightAfterFirst.push(new SegmentModelWithPaxInfo(
segment,
mockBoarding.booking.Passengers
));
});
});
});
AAA: Assert the results
- Test the results of your actions
- Properties should be defined
- Values should be parsed in your code correctly
describe('Given check-in flow', function () {
it('should list the checked-in segments', function() {
// ... already arranged data...
// ... already acted models...
// prove aboth flights with passengers are shown
expect(allFlights[0].availablePaxList.length).toBeGreaterThan(0);
expect(allFlights[0].isCheckingIn).toBe(true);
expect(allFlights[1].availablePaxList.length).toBeGreaterThan(0);
expect(allFlights[1].isCheckingIn).toBe(true);
// prove only the first flight is shown
expect(firstFlightOnly[0].availablePaxList.length).not.toBe(0);
expect(firstFlightOnly[0].isCheckingIn).toBe(true);
expect(firstFlightOnly[1].availablePaxList.length).toBe(0);
expect(firstFlightOnly[1].isCheckingIn).toBe(false);
// prove only the last flight is shown
expect(lastFlightAfterFirst[0].availablePaxList.length).toBe(3);
expect(lastFlightAfterFirst[0].isCheckingIn).toBe(false);
expect(lastFlightAfterFirst[1].availablePaxList.length).toBeGreaterThan(0);
expect(lastFlightAfterFirst[1].availablePaxList.length).toBe(2);
expect(lastFlightAfterFirst[1].isCheckingIn).toBe(true);
});
});
How not to TDD
A tale of how we learned TDD on Jetstar
Things that make TDD hard
- Inheriting a big project without tests
- Code that's not designed in units
TDD and Jetstar
TDD Juan-01
- TDD with existing code is hard
- TDD with end-of-flow states is hard
- Key takeaways
- Focus on new functionality
- Fake whatever you're not testing
Matty gets on board with TDD
- Didn't write tests on a new feature
- Didn't add tests when bugs came back
- Broke check-in process (TDD would have prevented it)
Summary: TDD in a nutshell
- Arrange, Act, Assert
- Developing by outcome
- Covering your ass
Summary: What not to do
- Adding tests to fully functional features
- Testing frameworks/artefacts you don't own
- Testing data outside the domain
TDD & Jetstar
By juanojeda
TDD & Jetstar
- 711