miércoles, 18 de julio de 2012

BDD & .NET = SpecFlow

Llevo tiempo detrás del XP, y todo lo que lo rodea, aprendiendo por mi cuenta TDD, patrones, buscando la excelencia técnica (que no se consigue con certificaciones, que las respuestas están puestas en internet), es decir, leyendo libros técnicos, viendo lo que otros han hecho y sobre todo programando (Katas, y código empresarial).

Ahora le toca al BDD. Me he visto y he practicado con este  vídeo. La verdad es que ahora entiendo un poco más lo que es, pero todavía me falta bastante por aprender.
Es importante tener instalado el SpecFlow , junto con el visual studio (en mi caso fue el monodevelop) en el sistema (en caso fue xubuntu 12.04), para poder hacerlo.Dejo el código resultante.
Primeramente la características (feature), el escanario que vas a testear.

Feature: Scoring
 In order to keep track of my score
 As a bowler
 I want to use automatic scoring system for some feedback
 
Scenario: Bowling a strike
 Given I am on the first frame
 When I bowl a strike
 Then I see a "X" and a message that says "Good Job!"
 And I Should hear "Green Day"

Scenario: Bowling a gutter ball as a first throw
 Given I am on the first frame
 When I bowl a gutter ball
 Then I should see an "0" and a message that says "You need lessons"

Scenario: Bowling a gutter balls in a frame
 Given I hace bowled a gutter ball already
 When I bowl another gutter ball
 Then I should see an "0" and a message that says "You need lessons"

Scenario: Finishing the game with nothing but gutter balls
 Given I bowled a gutter ball on every frame
 Then I should see an "0" and a message that says "you need lessons"
 And I Should hear "Sad Trombone"

Código que testea
using System;
using NUnit.Framework;
using TechTalk.SpecFlow;
using SuperBowlingScorer;

namespace Spec
{
 [Binding]
    public class ScoringSteps
 {
  SuperScorer _scorer;
  [Given(@"I am on the first frame")]
  public void GivenIamOnTheFirstFrame ()
  {
   _scorer = new SuperScorer ();
   Assert.AreEqual (1, _scorer.Frame);
  }

  [When(@"I bowl a strike")]
  public void WhenIBowlAStrike ()
  {
   _scorer.ScoreFirstBall (10);
  }

  [Given(@"I have bowled a gutter ball already")]
  public void WhenIHaveBowledAGutterBallAlready ()
  {
   _scorer = new SuperScorer ();
   _scorer.ScoreFirstBall (0);
  }
  
  [Then(@"I see a ""(.*)"" and a message that says ""(.*)""")]
  public void ThenISeeAXAndAMessageThatSaysGobJob (string score, string message)
  {
   Assert.AreEqual (message, _scorer.BowlerMessage);
   Assert.AreEqual (score, _scorer.Score);
  }
  
  [Then(@"I should hear  ""(.*)""")]
  public void ThenIShouldHearGreenDay (string song)
  {
   Assert.AreEqual (song, _scorer.SongToPlay);
  }
  
  [When(@"I bowl a gutter ball")]
  public void WhenIBowlAGutterBall ()
  {
   _scorer.ScoreFirstBall (0);
  }
  
  
  
  [When(@"I bowl another gutter ball")]
  public void WhenIBowlAnotherGutterBall ()
  {
   ScenarioContext.Current.Pending ();
  }
  
  
  [Given(@"I bowled a gutter ball on every frame")]
  public void GivenIBowledAGutterBallOnEveryFrame ()
  {
   _scorer = new SuperScorer ();
   for (int i = 1; i < 10; i++) {
    _scorer.ScoreFirstBall (0);
    _scorer.ScoreSecondBall (0);
   }
   
  }
 }
}
  

Código que implementa las funcionalidad a testear (S.U.T.)
using System;

namespace SuperBowlingScorer
{
 public class SuperScorer
 {
  public int Frame {
   get;
   set;
  }
  
  public string BowlerMessage {
   get;
   set;
  }
  
  public string Score {
   get;
   set;
  }
  
  public string  SongToPlay {
   get;
   set;
  }
  
  
  
  public int PinsTotal {
   get;
   set;
  }
  
  public int FirstBallScore {
   get;
   set;
  }
  
  
  public SuperScorer ()
  {
   Frame = 1;
  }
  
  public void ScoreSecondBall (int pinsKnockedDown)
  {
   PinsTotal += pinsKnockedDown;
   if (Frame < 10) {
    Frame ++;
   }
   
   if (IsGutterBall (pinsKnockedDown) && (FirstBallScore == 0)) {
    BowlerMessage = "You need lessons";
    Score = "0";
   }
   
   if ((Frame == 10)
    && (PinsTotal == 0)) {
    BowlerMessage = "You need the gutter bumpers";
    Score = "0";
    SongToPlay = "Sad Trombone";
   } 
  }
  
  public bool IsGutterBall (int pinsKnockDown)
  {
   return pinsKnockDown == 0;
  }
  
  public bool IsStrike (bool isFirstBall, int pinsKnockedDown)
  {
   return isFirstBall && (pinsKnockedDown == 10);
   
  }
  
  public void ScoreFirstBall (int pinsKnockDown)
  {
   if (IsStrike (true, pinsKnockDown)) {
    BowlerMessage = "Good Job!";
    Score = "X";
    SongToPlay = "Green Day";
   } else if (IsGutterBall (pinsKnockDown)) {
    BowlerMessage = "You'll better next time";
    Score = "0";   
   }
   FirstBallScore = pinsKnockDown; 
   PinsTotal += pinsKnockDown;
  }
 }
}
Creo que puede ayudar mucho a testear las aplicaciones y dar más calidad a los productos. Tengo que seguir investigando ...

sábado, 14 de julio de 2012

Install Sublime Text 2 In Xubuntu 12.04

this is the step that i've done for installing in my xubuntu 12.04

1._ Open the Web Browser
2._ Type uwall.tv and you look Audioslave (or your favorite group) in the reach box (of course, it's optinal)
3._ Open another tab
4._ Type http://www.sublimetext.com/2
5._ Select & Click your version of the sublime for your machine
6._ Save the file in the folder of your system.
7._ Open a terminal & go to the sublime file is
8._ Type:
tar -xvjf filename.tar.bz2

9._ Type:
sudo mkdir /opt/sublimetext2

10._ Type:
sudo mv 'the extracted content' /opt/sublimetext2/

11._ Type:
sudo touch /usr/bin/sublime

12._ Type:
sudo chmod 755 /usr/bin/sublime

13._ Type:
sudo gedit /usr/bin/sublime

14._ Type:
#!/bin/sh
export SUBLIME_HOME="/opt/sublimetext2" 
$SUBLIME_HOME/sublime_text $*
15._ Type:
sudo gedit /usr/share/applications/sublime.desktop

16._ Type:
[Desktop Entry]
Encoding=UTF-8
Name=Sublime
Comment=Sublime Text Editor
Exec=sublime
Icon=/opt/sublimetext2/Icon/128x128/sublime_text.png
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true

Source

jueves, 12 de julio de 2012

Sublime

I´ve discovered a new text editor, it may be the best text editor, faster than TextMate and other.
It´s Sublime Text

I´ve found a video explains some interesting things.

Starting with it.

It  seems nice!!!

miércoles, 11 de julio de 2012

Cosas para estudiar

Como el blog también me sirve como recordatorio. Apunto cosas que tengo que estudiar/leer/mirar/...
Mock vs. Stub, traducido
Agile Spain
S.O.L.I.D I, II y II
videos de Agile Spain
Material

Fuente: blog

sábado, 7 de julio de 2012

Arte callejero

Desde hace muchos años, creo que desde que estaba en el colegio y un chico de mi clase, se dedicaba a pintar. Ha despertado en mí una curiosidad por este tipo de arte urbano. Pero yo prefiero los bien hechos, los otros me dan la sesación de que ensucian (solo es una opinión personal). Sobretodo me fijo en la dibujos, más que en las letras.

Me he encontrado una galería que me ha llamado poderosamente la atención.

viernes, 6 de julio de 2012

Videos para aprender a programar de verdad

Leyendo cositas de Carlos Ble, me he encontrado con que hacía referencia a videos, para aprender a programar.

Me he visto el video que hablar en contra de los Null. Me acuerdo que mi jefe, me habló del patrón null y eso lo tengo que cambiar sí o sí, paraescribir mejor código. A practicarlo para interiorizarlo. Tienen muh buena pinta.

30J Huelga

Leyendo barrapunto, que el 30J había una huelga. Me he encontrado con unos interesantes comentarios (1, 2).

Me acuerdo una vez cuando un gestor, em dijo que los programadores son los nuevos esclavos del siglo XXI.
Puede que la única salida que tenga un informático en España sea por mar, aire o tierra. Pero también me llama poderosamente la atención las startup, que luchan por sacar su producto adelante con esfuerzo, ganas y mucho talento. Puede que ese sea una salida posible para cambiar las cosas.