FCI-Helwan blog

Just another FCI-H weblog

Source Control and Team Development Part 4

See previous parts here

The Only Chapter

In the first meeting, you defined a set of features, classes, and functional tests. You got Class A and Class B. You go home. You start writing a set of unit tests for your features. You write a skeleton of your classes. Just empty functions that returns dummy values. You compile, it compiles fine. Now you Check-In your files to the Source Control Server; just a single click. Before the check-in starts, unit tests are run, of course non of them are passed; you only have skeleton classes. Now check-in is complete. You go to sleep.
Next day you wake up, open you PC, in your home. You click “Update” to get the latest version of other people source code. Then you continue developing your classes. You implement seven functions. You compile, test, and find that 30% of tests have been passed. You check-in your code with a message stating a description of the change.

After 3 days, you find that some previously-passed tests have failed. You browse the history of the class that have failed the test, you click a single button and you have a side-by-side view of the current file version and the last-working version. The changed lines are highlighted for you. You compare only 3 lines, and decide to change one of them, and viola: that test have been passed again. You check-in your code with a message stating the correction.

Now you go to the second failed test, you remember that you have made a change that corrected that before and that maybe you have removed that change forgetting what it was for. You perform a search of the check-in messages using the keyword you used for that change, you got the file version that has that bug corrected, the exact lines that you changed to fix that bug is highlighted for you. You fix the current version with that code, and here it is; the test have been passed. You check-in your code with a message saying that you re-fixed that bug again.

Someday you find something inside someone else’s code that preventing your code from working. You fix it in his file. You check his file in with a message describing your change. When he checks-in his file with different changes, the server merges both of your files if you haven’t modified the same lines. The server lets him know that he doesn’t have the latest version and that a merge will happen, he previews the merge and approves it.

The big day has come. You sit together, you don’t have anything to do. The project was already integrated each day, and all the tests have been passed, you just go to college and get the maximum grade and go home having 4 feelings:
1- I love programming
2- We CAN make things right
3- I WANT to make a much bigger project next time
4- “Weeee are the champions”

See:

Test-Driven Development
Source Control

Other team management stuff:

Scrum

Other development techniques:

Extreme Programming (XP)

Finally, this is all about Agile Software Development

Big thanks to the MDC 2007 ;)

February 10, 2007 Posted by fcihelwanblogger | TeamDevelopment | | 1 Comment

Source Control and Team Development Part 3

See part 1 here
See part 2 here

Chapter 7

Suddenly some remembers that he has the flash memory that they used to transfer the last working version of the file. He gets is and replaces the non-working file, compiles, runs, and there it is. It works now. Still it doesn’t have the bugfix that they wanted to restore.

They accept that, and prepare to go to college, each one thinking how they are going to hide that bug from being noticed, or how they would convince the professor to have mercy on them if he noticed it.

Later that night, each one of them have four feelings:
1- I hate programming
2- We can never make anything right
3- I won’t spend much effort in such project again
4- WE ARE LOSEEERS :’(

The End

So what we have here ??
We have people who lost self-confidence thus will never be able to make something big, not because they can’t, but only because either they don’t want to, or they believe they can’t.

So, what’s the solution ? What do these people who make big software do ? Can this scenario ever be different ??

“Yes, sure it can be different, those people are just idiots!” Says someone smartly “They could’ve named the folders better!!”

Well, there is indeed a different scenario. But it is not like that smart one said.
This scenario is MUCH shorter than the former. It even consists of only one chapter.

To be con… Ops, sorry, I mean see the next article :D


February 10, 2007 Posted by fcihelwanblogger | TeamDevelopment | | No Comments Yet

Unit Test

Testing, testing, and testing, the most important phase especially in case working with group

So, testing anything before delivering it, is equal to develop it itself. And to avoid what
happens in teams refer to TeamDevelopment to know.

In this article, I’ll demonstrate the basic test that applied on functions in particular public functions and the called Unit Test. (Private functions will be the next)

Walk with me to test these simple functions:

public static int Add(int op1, int op2)
{
return op1 + op2;

}
public static int Subtract(int op1, int op2)
{
return op1 – op2;

}
public static int Multiply(int op1, int op2)
{
return op1 * op2;
}public static int Divide(int op1, int op2)
{
return op1 / op2;

}
static void Main(string[] args)
{
Console.WriteLine(
“Add: “ + Add(5, 0));
Console.WriteLine(
“Subtract: “ + Subtract(5, 0));
Console.WriteLine(
“Multiply: “ + Multiply(5, 0));
Console.WriteLine(
“Divide: “ + Divide(5, 0));
}

Good, but something waiting you

So, I’ll try and catch the Divide function to not get this error.

But till now I give up fatal error, what about logic error, should I write a program to test my function to by passing different parameters each time, yes, I should, what Unit Test actually do is that plus some information.

So, in our Math library, right click on any public method then select Create Unit tests, a cute dialog appeared in tree mode (Project, namespace, Class, Members, Methods) we then select Divide method to apply unit test on it, NOO, do not press Ok, we almost done, below output project: select create a new visual C# test project, enter a name for this unit test project say, DivideMethodUnitTest.

Going to Solution Explorer, we notice a new project has been added, yes, it’s DivideMethodUnitTest test project. It contains a class called [YourClassNameTest]
open it

[TestMethod()]

public void DivideTest(){//some code}

It generates a method to test Divide method, and some code, we going to put our
edits

int op1 = 5; // TODO: Initialize to an appropriate value
int op2 = 0; // TODO: Initialize to an appropriate value

int expected = 0;
int actual;
actual = UnitTestSample.Math.Divide(op1, op2);

Right click on DivideMethodUnitTest test project and select Set as startUp project, Ctr + F5 Test result window opened to inform me that the test has been faild : double click on failed it opens new windows contains some information about what has happened

Error Message:
Test method DivideMethodUnitTest.MathTest.DivideTest threw exception: System. DivideByZeroException: Attempted to divide by zero..

So, what should I do now is to catch this error, after that I’ll go to retest Divide method, and Comment Assert.Inconclusive(“A method…..”);

int op1 = 5; // TODO: Initialize to an appropriate value
int op2 = 0; // TODO: Initialize to an appropriate value
int expected = 0;
int actual;
actual = UnitTestSample.Math.Divide(op1, op2);

Congrats, your test window tells you Passed, double click on passed, it tells you Standard Console Output: Attempted to divide by zero

By passing more parameters I can get the logic error and the unit test informs me about that
int op1 = 5; // TODO: Initialize to an appropriate value
int op2 = 1; // TODO: Initialize to an appropriate value
int expected = 2;
int actual;
actual = UnitTestSample.Math.Divide(op1, op2);

Again, the test has been failed double click on failed it opens new windows contains some
information about what has happened

Error Message:
Assert.AreEqual failed. Expected:<2>, Actual:<5>. UnitTestSample.Math.Divide did not return the expected value.

So, give the right op1, op2, and expected values, to check for logic error

February 10, 2007 Posted by fcihelwanblogger | C# | | No Comments Yet

What’s new in C# 3.0 ? Part 2

Consider the following , iam working in a project and i made a class and i made a simple method inside this class after small period i wanted to modify or add something in this method all what i have to do just back to the code of this function and modify its code , this is good

but what if this Method was in dll or was in a sealed class or i wanted to add method in a class of the primitive data types ? what can i do ?? the Extension Method was the Solution.

eg.. i want to add a small Method to the string type which return the second word in a given string
it will be like this

static class beta{  public  static string GetSecondWord(this string input)  {      string  y="";      int count = 0;      bool flag = false ;      foreach  (char c in input)      {          if (c == ' ')          {              flag =      true;              count++;          }          if (flag == true && count == 1)          {                    if(    c != ' ')              y += c;

          }      }      return  y;  }}

Notes : 
  1. Make sure that the class is static
  2. Add this keyword before the type of the argument you want to extend.

so now you can write this code,

string x = “some string value”;
string y = x.GetSecondWord();

That’s it.See you in the Next Part isA

February 10, 2007 Posted by fcihelwanblogger | C# | | 3 Comments