Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

php - suggestions for unit testing exceptions -


consider method might throw exception descriptive text:

if ($somecondition) {     throw new \whatever\exception('dilithium exhausted'); } 

and elsewhere in method block might throw same exception, different text:

if ($anothercondition) {     throw new \whatever\exception('differentialator exploded'); } 

while writing unit tests class, create failure cases can verify these 2 exceptions thrown properly. in these failure cases, prefer to:

a) use @exceptionexpected in test method's docblock trap generic \whatever\exception class , subsequently ignore getmessage() text, assuming got right one? (seems bad idea.)

or:

b) use try/catch , assert caught exception's getmessage() text equals exact descriptive string you're expecting? (more resilient means changing tests whenever change error wording.)

or:

c) create separate exception each error case (e.g., \whatever\dilithiumexception , \whatever\differentialatorexception) , use @exceptionexpected each one.

i'm using b tending toward c. i'm curious others doing in same scenario. have guidelines determine, "at point error deserve own exception class versus more generic shared one?"

all of above.

a great, , use as possible because simplest. there case when not work:

/**  * @exceptionexpected fooexception  */ test() {   // code throw fooexception   ...   // purpose of test throws of fooexception } 

in case, test pass when should have failed because didn't testing. way deal use $this->setexpectedexception()

b great when might use information exception. rather using text of exception message prefer use code. have form validation exception packages problems encountered in data 1 exception. extending exception class becomes easy transmit deal of information internal error state external handling code.

c accomplishes same thing b, allows simplifying code relying on more classes. difference between these 2 subtle , tend rely on design aesthetic make decision.

tl; dr: use exception codes rather messages, , design use case rather unit tests.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -