rover2341
Is riding a roller coaster...Wee!
- Reaction score
- 113
Problem: You Create website/application, etc. that starts to get complex, and at the very least large in functionality. Some Functions that don't use any resources (sql, file, ect) can be tested using, functional and unit testing. But others that use sql become more tricky. My goal is address those issues here, and to get feedback on how others deal with this issue.
Functional:
Think User Does Something and expects a output. Could hit 1 function could hit 100.
Unit:
Think a sub section of code that is tested as a unit. Start high and work down.
Code Coverage:
Full Code coverage would mean every function in the program is covered.
Testing
1 Test Case For every expected out come.
Determine every expected outcome by reviewing the code.
Data Layer: Used to project Integrity of Data (SQL, File, Ect)
In Conclusion: This amount of testing should be sufficient if the framework your code is siting on is reliable .net java ect. And all cases to cover the code are covered.
It should not be required to test with 10000 test cases.
This can be done manual, or auto.
Input: 1 Output: One
Input: 2 Output: Two
Input: 3 Output: Exception: Invalid Selection
Input: 5, 5
Output: 10
Input null
5 Output: Error
Input: Tom
Output: 1
Input: Tom
Output: 2
Input: Frank
Output: Error Get Person Failed
This seems testable. But its only testable if the table has valid condition's.
For Example. What someone changed Points to Null on another function. or a invalid number like say -100
Then this function that relies on that wont work.
So you have 2 options. validate the things you work with any time you work with them Like add checks in this function for null and what not.
OR
Create a Data Layer:
This layer would have all query's in it. and would have validation that everything being updated/created/deleted is valid for the program to work. Instead of query's throughout the program.
If I am wrong on this, let me know! I personally don't do this as of today, but i plan to start doing it as of tomorrow. But I hate when people ask me does this work, and I cant tell them it does with a very high amount of certainty. Testing things at random or as i code, is not sufficient. Documenting these things are important, so you know whats been tested and what hasn't.
Things can quickly become invalid if anything related to any of the tests change. So test once i don't believe is the right way. But test efficiently, and effectively. Auto Testing is neat if you can get to that level.
Do you test your code? If so how?
Functional:
Think User Does Something and expects a output. Could hit 1 function could hit 100.
Unit:
Think a sub section of code that is tested as a unit. Start high and work down.
Code Coverage:
Full Code coverage would mean every function in the program is covered.
Testing
1 Test Case For every expected out come.
Determine every expected outcome by reviewing the code.
Data Layer: Used to project Integrity of Data (SQL, File, Ect)
In Conclusion: This amount of testing should be sufficient if the framework your code is siting on is reliable .net java ect. And all cases to cover the code are covered.
It should not be required to test with 10000 test cases.
This can be done manual, or auto.
Code:
public int Select(int x)
{
if(x == 1)
return "One";
else if(x == 2)
return "Two";
else
throw(new Exception("Invalid Selection");
}
Input: 1 Output: One
Input: 2 Output: Two
Input: 3 Output: Exception: Invalid Selection
Code:
public int Add(int x, int y)
{
return x + y;
}
Input: 5, 5
Output: 10
Input null
5 Output: Error
Code:
public int AddPoint(string name)
{
//Gets Person From SQL
Person x = GetPersonByName(name);
x.Points = x.Points + 1;
//Function saves Person
SavePerson(x)
return x.Points;
}
Input: Tom
Output: 1
Input: Tom
Output: 2
Input: Frank
Output: Error Get Person Failed
This seems testable. But its only testable if the table has valid condition's.
For Example. What someone changed Points to Null on another function. or a invalid number like say -100
Then this function that relies on that wont work.
So you have 2 options. validate the things you work with any time you work with them Like add checks in this function for null and what not.
OR
Create a Data Layer:
This layer would have all query's in it. and would have validation that everything being updated/created/deleted is valid for the program to work. Instead of query's throughout the program.
If I am wrong on this, let me know! I personally don't do this as of today, but i plan to start doing it as of tomorrow. But I hate when people ask me does this work, and I cant tell them it does with a very high amount of certainty. Testing things at random or as i code, is not sufficient. Documenting these things are important, so you know whats been tested and what hasn't.
Things can quickly become invalid if anything related to any of the tests change. So test once i don't believe is the right way. But test efficiently, and effectively. Auto Testing is neat if you can get to that level.
Do you test your code? If so how?