Jack M
Jack M

Reputation: 2574

Writing a unit test case

I have started using unit test in some of my projects and I have a small issue, I need to test one method and I have run out of ideas as an example: I have this

    public class Clients
    {
      Public Assignment AssignClient(int? clientRef, int? productRef)
       //Assignment is an enum that has success,Failure,etc...
        {
         If(!checkClientAge(int clientRef)) Return Assignment.Tooyoung;
          If(!checkClientAvailability(int clientRef)) Return Assignment.NotAvailable;
         If(! checkProductavailability(int productRef)) Return Assignment.ProductNotAvailable;
        }
     }

I done a mock on the client class and the AssignClient, but I am not sure what to do with three boolean methods, not sure if you have any idea on how I can mock these?

Upvotes: 0

Views: 155

Answers (1)

slugster
slugster

Reputation: 49985

If you are testing the Clients class then you don't mock it, you need a real instance. Instead you mock out the other classes it uses so that you can return known and predictable results from them and eliminate complications like database access, UI interaction, etc.

The AssignClient method is not a good candidate for unit testing unless the three calls to private methods set externally visible flags or properties - if they don't then there is nothing to measure or observe, you cannot tell if the test succeeded or failed.

Upvotes: 1

Related Questions