Birim Testi İsimlendirme Kılavuzu

Birim testleri yazarken kullanılmak üzere belirli, tutarlı bir isimlendirme ve biçimlendirme kılavuzu hedeflenmektedir.

Birim Testlerinin İsimlendirilmesi

Birim testlerini isimlendirmede genel yaklaşım şudur: MetotAdı_Koşul_BeklenenDavranış Birden fazla koşul varsa ifadeler And kelimesi ile ayrılır. Birden fazla sonuç davranışı varsa da aynı yapı kullanılır. (Davranışlar And ifadesi ile ayrılır)

Genel test isimleri

Name

Value

Genel test ismi formatı

[MethodName]_[Condition(s)]_[Behaviour(s)]

Koşul yoksa

[MethodName]_NoCondition_[Behaviour(s)]

Örnekler:

AuthenticateMember_ValidMember_LogOnMemberAndLogAuthenticationAndReturnSuccess
AuthenticateMember_InvalidMember_ReturnError
BlockMember_BlockedMemberIsFriendAndDeleteFriendFails_PreventFromBlockingMemberAndReturnError
GetBlockedMembers_NoCondition_ReturnBlockedMembers

Controller örnekleri:

AcceptRequestFromProfile_AcceptSucceeds_RedirectToReferrerPageWithSuccessMessage
ListFriendshipRequests_RequestTypeSent_DisplayRequestSentList
WithdrawRequest_WithdrawalFails_InformUser
LogOn_InvalidMemberModel_PreventFromLoggingOn
ResetPassword_ValidModel_RedirectToLogOnPageWithSuccessMessage
GetProfileShares_MemberCanDisplaySharesAndNoShares_ReturnShareListPartial
GetCities_CountrySupplied_ReturnCitiesOfSuppliedCountryAsJson

TestCase kullanılırsa

Name

Value

Beklenen davranış ortaksa

[MethodName]_[Entity]ConditionsInTestCases_[ExpectedBehaviour(s)]

Beklenen davranış ortaksa ve birden fazla koşul varsa

[MethodName]_SomeConditionAnd[Entity]ConditionsInTestCases_[ExpectedBehaviour(s)]

Beklenen koşul TestCase içinde belirtilmişse

[MethodName]_SomeConditionAnd[Entity]ConditionsInTestCases_ExpectedBehaviour(s)InTestCases

Örnekler:

IsMemberBlocked_BlockedConditionsInTestCases_ReturnBlockedStatus
UpdateFriendshipRequest_UpdateFailsAndNewRequestStatusInTestCases_ReturnFailResult
ViewProfileFriends_FriendsStatusInTestCases_PreventFromDisplayingProfileFriendsAndRedirectToNoProfileFoundPage

Validasyon testleri (FluentValidation)

Validasyon (FluentValidation) testlerinde kullanılan yapı normal metotlardan farklıdır. Testler hata ve başarı durumlarını kontrol edecek çiftler şekilde oluşturulur. "Validate" ön ekinin kullanımı zorunlu değil. Koşul_Davranış biçiminde de oluşturulabilir. Ancak "Validate" ön eki ile başlatılırsa gruplama daha anlamlı yapılabilir ve genel yapıya uyum sağlar.

Geçerli olmayan durum

Geçerli durum

Validate_ValueEmpty_HaveError

Validate_ValueNotEmpty_DoNotHaveError

Validate_ValueLengthNotInRange_HaveError

Validate_ValueLengthInRange_DoNotHaveError

Validate_ValuesDoNotMatch_HaveError

Validate_ValuesDoMatch_DoNotHaveError

Validate_ValueFormatInvalid_HaveError

Validate_ValueFormatValid_DoNotHaveError

Özel durumlara göre isimler verilebilir:

Geçerli olmayan durum

Geçerli durum

Validate_CityEmpty_HaveError

Validate_CityNotEmpty_DoNotHaveError

Last updated