Romain Tribes
2012-Feb-02 09:20 UTC
[rspec-users] Game development: how to test interactions like an attack?
Hello, I''m writing webgames with Rails and I want to test my code (and even TDD) but I''m really stuck figuring what to test. I read a lot of articles on the subject but I still don''t know what to do in my case: how to start? For instance, a simple interaction in most game: a character attacks another one. What should be tested? With words, here is what I can say about an attack: It''s an action from an attacker to a target. The attacker may have a weapon and the target may have an armor. In order to be successful, the attacker must hit the target, according to the combat skill of each actor and the precision of the weapon. When the target is hit, it receives damages according to the attacker power, the weapon damages and the resistance. A part of these damages may be absorbed by it''s armor. So, what could my specs be with that? I really can''t start? :( Thanks for your help!
Romain Tribes
2012-Feb-02 09:50 UTC
[rspec-users] Game development: how to test interactions like an attack?
Hello, I''m writing webgames with Rails and I want to test my code (and even TDD) but I''m really stuck figuring what to test. I read a lot of articles on the subject but I still don''t know what to do in my case: how to start? For instance, a simple interaction in most game: a character attacks another one. What should be tested? With words, here is what I can say about an attack: It''s an action from an attacker to a target. The attacker may have a weapon and the target may have an armor. In order to be successful, the attacker must hit the target, according to the combat skill of each actor and the precision of the weapon. When the target is hit, it receives damages according to the attacker power, the weapon damages and the resistance. A part of these damages may be absorbed by it''s armor. So, what could my specs be with that? I really can''t start? :( Thanks for your help!
Matt Wynne
2012-Feb-02 10:45 UTC
[rspec-users] Game development: how to test interactions like an attack?
On 2 Feb 2012, at 09:50, Romain Tribes wrote:> Hello, > > I''m writing webgames with Rails and I want to test my code (and even TDD) but I''m really stuck figuring what to test. > I read a lot of articles on the subject but I still don''t know what to do in my case: how to start? > > For instance, a simple interaction in most game: a character attacks another one. What should be tested? > With words, here is what I can say about an attack: > > It''s an action from an attacker to a target. > The attacker may have a weapon and the target may have an armor. > In order to be successful, the attacker must hit the target, according to the combat skill of each actor and the precision of the weapon. > When the target is hit, it receives damages according to the attacker power, the weapon damages and the resistance. > A part of these damages may be absorbed by it''s armor. > So, what could my specs be with that? I really can''t start? :(Have you started to design a domain model for this? Could we see a picture? cheers, Matt -- Freelance programmer & coach Author, http://pragprog.com/book/hwcuc/the-cucumber-book Founder, http://www.relishapp.com/ Twitter, https://twitter.com/mattwynne -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120202/e8b98be3/attachment-0001.html>
Julian Leviston
2012-Feb-02 11:36 UTC
[rspec-users] Game development: how to test interactions like an attack?
I always find it''s very good to start simply. Make the simplest spec you can imagine, then the next, and so on... What is a spec? Some of this stuff might seem so obvious... for example... when you start playing your game, you expect that it''ll present you with something... write a test for that. Basically any time you''re doing something yourself to run your code, you should be able to spec it. That way you don''t have to manually test things out. So I''ve got a basic question: have you started building your game? Do you have any idea of the requirements at all? Julian On 02/02/2012, at 8:20 PM, Romain Tribes wrote:> Hello, > > I''m writing webgames with Rails and I want to test my code (and even TDD) but I''m really stuck figuring what to test. > I read a lot of articles on the subject but I still don''t know what to do in my case: how to start? > > For instance, a simple interaction in most game: a character attacks another one. What should be tested? > With words, here is what I can say about an attack: > > It''s an action from an attacker to a target. > The attacker may have a weapon and the target may have an armor. > In order to be successful, the attacker must hit the target, according to the combat skill of each actor and the precision of the weapon. > When the target is hit, it receives damages according to the attacker power, the weapon damages and the resistance. > A part of these damages may be absorbed by it''s armor. > So, what could my specs be with that? I really can''t start? :( > > Thanks for your help! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Justin Ko
2012-Feb-02 11:44 UTC
[rspec-users] Game development: how to test interactions like an attack?
On Feb 2, 2012, at 2:20 AM, Romain Tribes wrote:> Hello, > > I''m writing webgames with Rails and I want to test my code (and even TDD) but I''m really stuck figuring what to test. > I read a lot of articles on the subject but I still don''t know what to do in my case: how to start? > > For instance, a simple interaction in most game: a character attacks another one. What should be tested? > With words, here is what I can say about an attack: > > It''s an action from an attacker to a target. > The attacker may have a weapon and the target may have an armor. > In order to be successful, the attacker must hit the target, according to the combat skill of each actor and the precision of the weapon. > When the target is hit, it receives damages according to the attacker power, the weapon damages and the resistance. > A part of these damages may be absorbed by it''s armor.What you just listed ^^ is the behavior of the system. The great thing about BDD is you can start _without_ needing to know the implementation details. The first step you can take is to setup some high level, outside-in testing. These tests interact with your program the same way as a user would. You''ll hear these tests called many different names: acceptance, integration, functional, application, system, etc. I don''t believe there is a correct term anymore, as everyone interprets the definitions differently. In the case of Ruby, you have excellent tools available for these tests: RSpec, MiniTest, Cucumber (used with RSpec or MiniTest). Personally, I prefer to use only RSpec, so let''s use that as an example. Pick a simple behavior to start off with. A good one is something that the user _has_ to do first. For example, in a Rails app, this would be signing up: # project/spec/functional/signing_up_spec.rb describe ''Signing up'' do context ''by visiting the sign up page'' do before { go_to_the_sign_up_page } context ''and submitting the sign up form with valid data'' do before { submit_the_sign_up_form_with_valid_data } it ''redirects to the dashboard page'' do expect_to_be_on_the_dashboard_page end end end end Great, now I have my first spec. Obviously, if you tried to run this, it would completely fail since you haven''t written any implementation code. At this point, writing more high level tests doesn''t make sense because we haven''t got the first one to pass. Let''s focus on doing that. Alright, so as we can see from our spec, the first thing it does is "visits the sign up page". Okay, we need a sign up page. The sign up page is a single entity, and we''re no longer concerned with how it interacts with other parts of the system. Therefore, we need to drop down to the "unit" level, and subsequently create a unit test for this entity: # project/spec/unit/sign_up_page_spec.rb describe SignUpPage do context ''given a coupon code'' do it ''sets a hidden field called "coupon_code" with its value as the code'' do expect_a_hidden_field_with_a_particular_value end end end Notice how we are still focusing on behavior. The difference is, we are only concerned with the behavior of just this entity/unit, not on its role or interactions in the system. Because of this, you''ll sometimes see people call them "isolated unit tests". After you get the unit test to pass, you can check to see if the high level test can pass. The BDD process involves jumping back and forth between unit and high level tests. However, the high level tests are _always_ your guide. You drive the high level tests, and in turn they drive the unit tests. I think this is enough to get you started, but looking at your post, this could be your first high level test: describe ''Attacking'' do let!(:attacker) { create_attacker } let!(:target) { create_target } context ''on the playing page'' do before { go_to_the_playing_page } describe ''when an attacker hits a target'' do before { hit_target(attacker, target) } it ''displays the damages on the target'' do expect_page_to_display_the_correct_damage_amount end end end end> When the target is hit, it receives damages according to the attacker power, the weapon damages and the resistance.> So, what could my specs be with that? I really can''t start? :( > > Thanks for your help! > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
George Dinwiddie
2012-Feb-02 17:24 UTC
[rspec-users] Game development: how to test interactions like an attack?
Romain, On 2/2/12 4:50 AM, Romain Tribes wrote:> Hello, > > I''m writing webgames with Rails and I want to test my code (and even TDD) but I''m really stuck figuring what to test. > I read a lot of articles on the subject but I still don''t know what to do in my case: how to start? > > For instance, a simple interaction in most game: a character attacks another one. What should be tested? > With words, here is what I can say about an attack: > > It''s an action from an attacker to a target. > The attacker may have a weapon and the target may have an armor. > In order to be successful, the attacker must hit the target, > according to the combat skill of each actor and the precision of the > weapon. > When the target is hit, it receives damages according to the attacker > power, the weapon damages and the resistance. > A part of these damages may be absorbed by it''s armor. > So, what could my specs be with that? I really can''t start? :(Start with the simplest scenario you can imagine. What would happen if the attacker had no weapon and the target had no armor? I can imagine scenarios with each having little skill, with each having great skill, and the two unbalanced scenarios where one has great skill and the other little. Is it possible for the attacker to miss? - George -- ---------------------------------------------------------------------- * George Dinwiddie * http://blog.gdinwiddie.com Software Development http://www.idiacomputing.com Consultant and Coach http://www.agilemaryland.org ----------------------------------------------------------------------
Romain Tribes
2012-Feb-03 01:06 UTC
[rspec-users] Game development: how to test interactions like an attack?
Thanks for your attention and your answers! I worked on that the whole afternoon: it''s really timeconsuming when you are not used to test! My code is on GitHub : https://github.com/Sephi-Chan/LearnToTest As I said I read a lot of stuff about testing and TDD. Unfortunately, most of the time it''s for systems with very little business logic and I don''t believe I can learn good software design with simplistic systems (todo-lists/blogs/...). It''s why I want to build something more interesting and focus on the business logic: not the controllers/views stuff. Anyway I hope you''ll keep helping me to review and give me precious advices. :) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20120202/e50cc9a1/attachment.html>