Testing - Validation - Stability

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.

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?
 

Slapshot136

Divide et impera
Reaction score
471
I usually stick to unit tests (and attempt to have enough to test each function), but have also had the same issues where testing SQL or similar isn't really feasible.. the best I have gotten is doing a "unit test" on stored procedures, and then just relying on those - for higher-level tests I will create mock clients or situations that test the entire code (i.e. a test suite in soap UI or similar), but really those are more of an addition to the documentation than for testing purposes

not really sure I understand how your "data layer" is supposed to work - it seems like it would be at least as complicated as a correctly configured back-end database (with the proper data/structure in it)
 

seph ir oth

Mod'n Dat News Jon
Reaction score
262
I've spent a good deal of time writing automated test cases for the service layer calls I've written, and while it's a different database, the concept is all the same: keep your service calls simple, clean, and only grab the barebones. If you have to get a lot of data, break it up into smaller calls if possible. If, for efficiency sake, you would rather do a bulk call for something, then expect longer times for the function to finish.

Not sure if you're working with .NET or not but check this out:

https://msdn.microsoft.com/en-us/magazine/dn818493.aspx

It's best to run asynchronous calls on db unit tests.

EDIT: Noticed I'm late to the party by nearly a month. Oh well ;)

EDIT2: As for valid conditions for testing against db's, you should always have a "test db" on-hand. One that can be reset and re-tested. That way the data is always the same at the start and is slated for being reset afterwards. SQL should support reverting back to a specific state using a .bak file, no? Create a unit_test.bak file, and write a little VB script that executes a db revert then runs the db unit tests.
 

Accname

2D-Graphics enthusiast
Reaction score
1,462
I never made a website but I would use abstraction. Build a facade around the data base and only interact with the facade from the point of view of your application. Then, have different implementations of the facade; for testing use a memory-based backend. For the actual implementation use a regular data base. Then make a mathematical prove that your memory-based implementation and your data base implementation work exactly the same way (same inputs => same outputs) and you are golden.
If your problem is with synchronization and having to fear that one function might result in a bug in another function because of a dirty write I would suggest always checking data when writing. This has, of course, a negative effect on performance, but it can always be deactivated when deployed. If it doesnt break during testing / debugging then its not too likely to break during use.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top