Unit testing method name standard for overloaded methods

I have read several posts which discuss coding standard for naming the unit test methods for improving readability.

I follow this NameOfMethod_ExpectedBehavior_WhenSomeScenario, but now I am confused as to how should I continue with this in the face of overloaded methods. There can be several methods with same name but different signatures.

Can someone please suggest me how to incorporate overloading in method names?

For example: Java Code

class ClassUnderTest{
    public int method1(){
    }

    public int method1(int arg){
    }
}

Now I need to test both the methods individually from my test case. I am thinking of some standard that is applicable for this scenario.

The overload being tested doesn’t really matter. The state really handles the decision of which overload to call.

So if you have a ToString method on a DateTime object with one that takes no arguments and one that takes a format string you would have.

ToString_1-3-2014T00:00:00_JanThirdDefaultFormat

and

ToString_1-3-2014_JanThirdDateOnly

Since your test methods typically don’t have different signatures (I guess they will seldom have parameters), you need a different way to distinguish them. As long as the WhenSomeScenario part is different for different overloads, you don’t have to provide any special measures:

 MyMethod_Returns0_WhenCalledWith1     // testing MyMethod(int)
 MyMethod_Returns0_WhenCalledWith1_2   // testing MyMethod(int,int)

does it.

If that does not work in specific cases, because you have a more abstract scenarios to test, where the names don’t reflect the input parameters directly, you need something like

  NameOfMethodSignaturecode_ExpectedBehavior_WhenSomeScenario

You still have to decide what you fill in for the Signaturecode, depends a little bit on your personal taste. When you are willing to use very long method names, you could use just add a concatenation of the typenames, like

 MyMethodInt_Returns0_WhenCalledBeforeInitialization     // testing MyMethod(int)
 MyMethodIntInt_Returns0_WhenCalledBeforeInitialization // testing MyMethod(int,int)

If you think the method names become too long that way, you have to use some kind of shortage for the typenames (for example, analogous to the shortages in Hungarian notation). What I would avoid is to use some kind of index 1,2,3,… to distinguish the test methods, this gives you no clue which test method is for which overload.

Methods typically require more than a single unit test. I have found GIVEN…WHEN…THEN naming to be superior in most cases. It’s ok to have multiple tests that say GIVEN_…WHEN_overloaded_method_THEN…

The method names get rather long but it doesn’t matter because they are never called explicitly.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật