Monday, December 8, 2014

Setup What? Origins Of Four Step Unit Testing in iOS

When I’m at my desk during the week and have written new code, I always create a new unit test file, and it looks something like this:

I asked myself two questions:
  1. Why do I create a new testcase class for every new class?
  2. Why do all of the tests I have always contains four-steps?

History of XCTest and xUnit


XCTest is based off of OCUnit and falls under the family of xUnit testing frameworks. xUnit is the collective name for several unit testing frameworks that derive their structure and functionality from Smalltalk’s SUnit [1], notably JUnit, which was also authored by Kent Beck [2]. In March 1998, OCUnit was written by Sen:te using Kent Beck’s description of the Smalltalk testing framework [3]. Understanding the origins of XCTest and JUnit helped me discover that most of the testing habits I have today all derive from Kent Beck’s Simple Smalltalk Testing: With Patterns.

One Testcase Class

I recommend that developers write their own unit tests, one per class. The framework supports the writing of suites of tests, which can be attached to a class. I recommend that all classes respond to the message “testSuite”, returning a suite containing the unit tests.
— Kent Beck, Simple Smalltalk Testing: With Patterns

It was Kent Beck’s philosophy that led to the practice of creating one testcase class per class. Beck believed that test logic should be encoded as a single test method on some class [4], and a testcase class gives you a place to group these similarly related test methods [5]. Making test methods instance methods of a testcase class and creating a testcase object for each test, allows us to manipulate the test methods at runtime, such as running a single test case, a group of test cases, or skipping a particular test case [6].




Source: xUnitPatterns


Four-Phase Test




Source: xUnitPatterns

The idea of having a setup method, a test method, then a tearDown method come from Beck’s work, and has been formalized into what is called the Four-Phase Test. In the Four-Phase Test, every test has four distinct phases that are executed in sequence: setup, exercise SUT (system under test), result verification, and fixture teardown [6]. The purpose of creating clear distinctions in the phases was to make the system under test extremely obvious.

The inspiration for the design was based around the fact that automated tests should serve at least two purposes:

First, they should act as documentation of how the system under test (SUT) should behave; we call this Tests as Documentation. Second, they should be a self-verifying executable specification.
— Gerard Meszaros, xUnitPatterns

The Four-Phase Test can be thought of as a state machine. In the fixture setup phase, the test establishes the prior state of the world. In the second phase we interact with the SUT, which transitions us to the next state. In the third phase we analyze the post state of the world and verify that it meets our expectations. Then in the fourth phase, we reset the state of the world prior to running the test.

Conclusion

Unit testing may sometimes become a laborious process, so it’s refreshing to take a step back and understand why we do the things that we do. The inspiration of unit testing frameworks in iOS or OS X has been around since the first version of SUnit in 1994 [7], and given that unit testing hasn’t changed much since then, it seems that the paradigms of one testcase class per class and four-phase testing are here to stay.


Sources


[1] "XUnit." Wikipedia. January 12, 2014. Accessed December 08, 2014. http://en.wikipedia.org/wiki/XUnit.

[2] "JUnit." Wikipedia. January 12, 2014. Accessed December 08, 2014. http://en.wikipedia.org/wiki/JUnit.

[3] "IPhone Unit Testing | Sen:te." Sente RSS. Accessed December 08, 2014. http://www.sente.ch/?p=535&lang=en.

[4] "Test Method." At XUnitPatterns.com. Accessed December 08, 2014. http://xunitpatterns.com/Test%20Method.html.

[5] "Testcase Class." At XUnitPatterns.com. Accessed December 08, 2014. http://xunitpatterns.com/Testcase%20Class.html.

[6] "Four-Phase Test." Four Phase Test at XUnitPatterns.com. Accessed December 08, 2014. http://xunitpatterns.com/Four%20Phase%20Test.html.

[7] "Ten Years Of Test Driven Development." Ten Years Of Test Driven Development. Accessed December 08, 2014. http://c2.com/cgi/wiki?TenYearsOfTestDrivenDevelopment.

37 comments :

Aashi siva said...

It’s really amazing that we can record what our visitors do on our site. Thanks for sharing this awesome guide. I’m happy that I came across with your site this article is on point,thanks again and have a great day. Keep update more information..

J2ee Training in Chennai Thiruvanmiyur

Unknown said...


the blog is very useful, interesting and informative. thank you for sharing the blog with us. keep on updating.
Informatica Training in Chennai Thiruvanmiyur

Haritha said...

You did a great job.. Thanks a lot for sharing this useful informative post with us.. Keep on blogging like this informative post with us, to develop my career in the right way.
Hadoop Training in Chennai Guindy

Unknown said...

Superb i really enjoyed very much with this article here. Really its a amazing article i had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your updation.
Digital Marketing Company in Chennai

Ancy merina said...
This comment has been removed by the author.
Unknown said...

Thank you for sharing the wounderful Article!
Major Cities
Packers and Movers in Pune
Packers and Movers in Bangalore
Packers and Movers in Chennai
Packers and Movers in Delhi
Packers and Movers in Mumbai
Packers and Movers in Gurgaon
Packers and Movers in Hyderabad

Aarijali said...

I got what you mean , a debt of gratitude is in order for posting .Woh I am cheerful to discover this site through google. Tax Enquiry Accounts

robinjack said...

I as of late discovered numerous helpful data in your site particularly this web journal page. Among the bunches of remarks on your articles. A debt of gratitude is in order for sharing. HMRC Tax Investigation Accountants

seo said...

Really great post. I just unearthed your online journal and needed to say that I have truly delighted in perusing your blog entries. Any way I'll be subscribing to your food and I trust you post again soon. Huge much obliged for the valuable data. HMRC Tax Enquiry Advice

seo said...

Much obliged to you for such an elegantly composed article. It's brimming with astute data and diverting depictions. Your perspective is the best among numerous. Let Campaign Tax Enquiry

basha said...

Superb blog I visit this blog it's extremely marvelous. Interestingly, in this blog content composed plainly and justifiable. The substance of data is exceptionally instructive.
oracle fusion financials classroom training
Workday HCM Online Training
Oracle Fusion Financials Online Training
Oracle Fusion HCM Online Training
Oracle Fusion SCM Online Training
Oracle Fusion HCM Classroom Training

Packers And Movers Mumbai said...

Excellent post! I must thank you for this informative read. I really enjoyed reading it,c you’re a great author.Please visit here @ Packers And Movers Mumbai

shanvibhardwaj said...

malviya nagar escorts ###
mayur vihar escorts ###
greater kailash escorts ###
munirka escorts ###
nehru place escorts ###
paharganj escorts ###
pitampura escorts ###

rihanakhan said...

thane call girls ###
kurla call girls ###
goregaon call girls ###
powai call girls ###
chembur call girls ###
vashi call girls ###
bhandup call girls ###
dadar call girls ###
versova call girls ###

aafreensaifi said...

kurla call girls ##
lokhandwala call girls ##
lower parel call girls ##
malad call girls ##
chembur call girls ##
churchgate call girls ##
mira bhayandar call girls ##
mira road call girls ##

Unknown said...

High Profile Call Girls Pune ###
High Profile Call Girls Pune ###
High Profile Call Girls Pune ###
High Profile Call Girls Pune ###
High Profile Call Girls Pune ###
High Profile Call Girls Pune ###
High Profile Call Girls Pune ###
High Profile Call Girls Pune ###

Unknown said...

vasundhara escorts$$
kaushambi escorts$$
ghaziabad escorts$$
greater noida escorts$$
noida extension escorts$$
noida escorts$$
kalkaji escorts$$

Unknown said...

College Call Girls In Thane a threesome is sometimes considered the holy grail of sexual encounters. A lot of men want to experience one at some point in their lives, but it can be difficult to transition into one naturally.

$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts
$$ Housewife Escorts

M S Jasmin said...

If you are thinking to give it a shot with professional Dwarka Call Girls Service then you should be going for over other call girls in the industry. You are supposed to get so many amazing features and qualities.

$$ Female Escorts In Defence colony
$$ Female Escorts In South ex
$$ Female Escorts In Safdarjung enclave
$$ Female Escorts In Greenpark
$$ Female Escorts In Mahipalpur
$$ Female Escorts In Chatarpur
$$ Female Escorts In Chanakyapuri
$$ Female Escorts In Dwarka
$$ Female Escorts In Rohini

Unknown said...

high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####
high profile call girls whatsapp number ####

anushkadase said...

escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####
escorts service in delhi ####

Unknown said...

Sexy Russian Call Girls in Cr Park, Russian Escorts in Cr Park

Independent call girls service ###
Independent call girls service ###
Independent call girls service ###
Independent call girls service ###
Independent call girls service ###
Independent call girls service ###
Independent call girls service ###
Independent call girls service ###
Russian Call Girls in Cr Park ###

anushkadas said...

aerocity independent escorts classified ####
aerocity independent escorts classified ####
aerocity independent escorts classified ####
aerocity independent escorts classified ####
high profile escort in delhi ####
high profile escort in delhi ####
high profile escort in delhi ####
high profile escort in delhi ####
high profile escort in delhi ####

siabansal said...

call girls service in kapashera ###
call girls service in mayur vihar ###
call girls service in mehrauli ###
call girls service in munirka ###
call girls service in paharganj ###
call girls service in pitampura ###
call girls service in south ex ###

russiancallgirlsms said...

high profile call girls service ###
high profile call girls service ###
high profile call girls service ###
high profile call girls service ###
high profile call girls service ###
high profile call girls service ###
high profile call girls service ###
high profile call girls service ###
high profile call girls service ###

Unknown said...

independent housewife escorts $$$
cheap rates housewife escorts $$$
sexy call girls whatsapp number $$$
cheap rates call girls $$$
independent escorts classified $$$
independent housewife escorts $$$
cheap rates housewife escorts $$$
sexy call girls whatsapp number $$$

janvikaushik said...

I am Noor Escorts an Noida escorts & College Call Girl in Noida available 24 hours for erotic escort services in Noida Call Girls.so you can fulfill your dreams with Cheap Call Girls In Noida Escorts.
Escorts Near Hotel Taj Palace Hotel Delhi
Escorts Near Hotel The Ashok New Delhi
Escorts Near Hotel The Claridges New Delhi
Escorts Near Hotel The Grand Vasant Kunj
Escorts Near Hotel The Imperial New Delhi
Escorts Near Hotel The Lalit New Delhi

Sonam Kumari said...

Those Russian Escort In Delhi can be reached directly via their website. You can hire those ladies for adult enjoyments as well for other purposes. You can hire those dashing ladies to enjoy your weekend at any nearby place where you can enjoy for a long time.

$$ Escorts Near Hotel Savoy Suites Noida
$$ Escorts Near Hotel The Roseate New Delhi
$$ Escorts Near Hotel Vivanta By Taj Ambassador Delhi
$$ Escorts Near Hotel Vivanta By Taj Dwarka
$$ Escorts Near Hotel WelcomHotel Dwarka ITC Hotel Group
$$ Escorts Near Hotel Radisson Blu MBD Noida
$$ Escorts Near Hotel Savoy Suites Noida

russian models call girls said...

high profile call girls ghaziabad ###
high profile call girls ghaziabad ###
high profile call girls ghaziabad ###
high profile call girls ghaziabad ###
high profile call girls ghaziabad ###
high profile call girls ghaziabad ###
high profile call girls ghaziabad ###
high profile call girls ghaziabad ###

Priyasharma said...

## Crossing Republik Call Girls

## Vasundhara Call Girls

## Jor Bagh Call Girls

## Shanti Niketan Call Girls

## Gulmohar Park Call Girls

## Panchsheel Enclave Call Girls

## Safdarjung Call Girls

## Jangpura Extension Call Girls

## Kailash Colony Call Girls

## Green Park Call Girls

delhimodelclub said...

High Profile Call Girls ###
russian escorts ###
high class escorts ###
Celebrity Model Escorts ###
High Profile Indepenent Escorts ###
High Profile Call Girls ###
russian escorts ###
high class escorts ###

Roshni Mishra said...

Call/Whatsapp+91- 9873777170 Delhi Call Girls & Delhi Escorts Service | Russian Model along with exciting call girls facility available.visit my blog:-
Anand Lok Call Girls &&
New Friends Colony Call Girls &&
Amrita Shergill Marg Call Girls &&
Hauz Khas Enclave Call Girls &&
Panchsheel Marg Call Girls &&
Nizamuddin West Call Girls &&
Punjabi Bagh Call Girls &&
Naraina Vihar Call Girls &&
Model Town Call Girls &&
Defence Colony Call Girls &&

periyannan said...

Thanks for the information... I really love your blog posts..
artificial intelligence internship | best final year projects for cse | internship certificate online | internship for mba finance students | internship meaning in tamil


brijesh kumar said...

Where To Cut Led Strip. Cut with a pair of scissors. The ideal place to cut in a led strip is the copper connections located at every two inches of the led strip.

Laila Thakur said...

Hi I read your blog and found that your blog is full of informative content. So keep posting thanks for share this article. Your article is very amazing. I like your article. thanks you ones again.

B.A. Time Table 2022 - BA 1st 2nd 3rd Year Exam Date Sheet
B.A. 1st Year Time Table 2022
B.A. 2nd Year Time Table 2022
B.A. 3rd Year Time Table 2022

Import Globals said...

Awesome blog, thank you so much for sharing such an amazing information with us. Visit Import Globals for Vietnam Import and Export Data Services at Vietnam customs.
Vietnam Export Data

naresh said...

Hi,
I appreciate your thoughts about the thought-provoking blog. It makes me happy to hear that you've received useful ideas, and I'm grateful for the opportunity to foster important interactions. Your appreciation for my dedication is quite touching, and I can't wait for the opportunity to create another amazing blog that offers you joy. Your words of support mean a lot to me; thank you very much!
Here is some OTM information that you might find useful.
OTM Training