0

I am new to c#. I do have some experience testing javascript. I was looking at assessing this test similar to checking for a method to be called in with a spy via sinon.

However, I am not truely sure what to test. As I noted I am pretty new to c# and am doing testing to get a feel for how the code works.

Here is the private method that I need to test for

 private TicketResponse.PaymentType GetPaymentType(TicketResponse.FormOfPaymentCreditCard paymentType, VCR_DisplayRSTicketingInfosTicketingInfoTicketingTicketDataTourInfo tourInfo)
    {

I read that I test the interfaces. So I am testing something along these lines?

 public enum PaymentType
{
    CASH, CREDIT_CARD, NITP, TRAVEL_CREDIT, GIFT_CARD, JETBLUE_REWARDS, NONE, CHECK, EXCHANGE
}

Any insight would be super helpful thanks.

Winnemucca
  • 3,309
  • 11
  • 37
  • 66
  • 1
    The general consensus is your unit tests should be testing the public methods for expected behavior; the associated private methods will be tested through the public methods. – Metro Smurf Jul 21 '16 at 20:44
  • Here is an update to my question. http://stackoverflow.com/questions/38514315/what-to-test-for-in-private-methods-on-c. – Winnemucca Jul 21 '16 at 21:04

2 Answers2

2

The usual testing methodology is to only test the public interfaces to your class. Testing the private methods usually creates brittle tests, and doesn't necessarily test the public endpoints that other client classes will be using.

If you only test the public interface, you make it easier to change the details/implementation (in the private methods) without breaking the tests.

Oleksi
  • 12,947
  • 4
  • 56
  • 80
  • Ok this makes more sense. I was thinking along the lines of a spy for c# to see if the method was called. I will update my question further. I still do have a few questions on in regards to the public interface. Thanks – Winnemucca Jul 21 '16 at 20:55
  • @stevek If you have other questions, I would start a new question since this has been marked as a duplicate. – Oleksi Jul 21 '16 at 21:00
  • Ok I moved it here. http://stackoverflow.com/questions/38514315/what-to-test-for-in-private-methods-on-c – Winnemucca Jul 21 '16 at 21:03
0

You can't test a private method because it's not visible outside the class in which it's defined.

If you want your method to be testable it has to be public or have a public wrapper.

Private methods are usually tested indirectly via tests on the public methods that call them.

ChrisF
  • 134,786
  • 31
  • 255
  • 325