I'm having issues modeling my tests to drive from the .run
method down to the inner workings of the app.
The .run
method is the sole point of entry for the application which has yet to be written. What you see below it just a quick mockup of how it could work.
.run
is basically a factory which creates and instance of Car
, adds some Wheels & Doors and finally returns a string representation of the car.
Because of this, I'm not sure how to write my first tests to get started.
class Car
attr_accessor :wheels, :doors
def initialize
@wheels = []
@doors = []
end
def self.run(wheels, doors)
car = Car.new
car.wheels = Car::Wheel.load_json(wheels)
car.doors = Car::Door.load_json(doors)
car.build.to_s
end
end
Car.run(wheels_json, doors_json)
Some thoughts I had:
- I could write an integration test but that won't really drive the development since an integration test would simply check that calling
.run
with two variables (wheels and doors) with json content in them will spit out a string representation of a car. I'll have to write a hell of a lot of code to make that test to pass. - If
.run
was returning an instance ofCar
I could test by grabbing the returned instance but I can't do that since the method returns a string.
To be clear, the question is: Given the above code, how would you start testing to help you drive down and build the rest of the application.
Aucun commentaire:
Enregistrer un commentaire