If you think..

If you think you are too small to make a difference, 

try sleeping with a mosquito.

-

Dalai Lama

iOS testing

In this post you can get some info about iOS app testing. After tried some tools about iOS testing, I focused my effort in KIF (for UI testing) and GHUnit (for unit testing). Using those 2 tools, I’m able to test almost any part/piece of an iOS app. Let’s see a bit more in detail how those tools work.

 

KIF (UI testing)

It is an Integration Testing Framework, which stands for Keep It Functional. It uses accessibility label to create automation of iOS app. KIF runs into your iOS phone and simulator too. Tests are written in Objective-C.

There are 3 classes in KIF to write tests, a Controller, a Scenario and a Step.

The Controller (KIFTestController) is composed of a list of Scenarios (KIFTestScenario),  whereas a Scenario is composed of a list of Steps (KIFTestStep). A step is a simple action which is used to imitate a user interaction.

Note: KIF uses undocumented APIs, so do not make it into production code otherwise your app submission will be denied by Apple.

To install KIF, see git url: https://github.com/square/KIF#installation

 

Example (from https://github.com/square/KIF#example)

 # File Controller

#import “EXTestController.h”

#import “KIFTestScenario+EXAdditions.h

 

@implementation EXTestController

 

- (void)initializeScenarios;

{

[self addScenario:[KIFTestScenario scenarioToLogIn]];

// Add additional scenarios you want to test here

}

@end

 

 

#Scenario (list of steps)

#import “KIFTestScenario+EXAdditions.h”

#import “KIFTestStep.h”

#import “KIFTestStep+EXAdditions.h”

 

@implementation KIFTestScenario (EXAdditions)

 

+ (id)scenarioToLogIn;

{

KIFTestScenario *scenario = [KIFTestScenario scenarioWithDescription:@"Test that a user can successfully log in."];

[scenario addStep:[KIFTestStep stepToReset]];

[scenario addStepsFromArray:[KIFTestStep stepsToGoToLoginPage]];

[scenario addStep:[KIFTestStep stepToEnterText:@"user@example.com"

intoViewWithAccessibilityLabel:@"Login User Name"]];

[scenario addStep:[KIFTestStep stepToEnterText:@"thisismypassword"

intoViewWithAccessibilityLabel:@"Login Password"]];

[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"Log In"]];

 

// Verify that the login succeeded

[scenario addStep:[KIFTestStep

stepToWaitForTappableViewWithAccessibilityLabel:@"Welcome"]];

 

return scenario;

}

@end

 

 

GHUnit (Unit  testing)

 It is a test framework for Mac OS X and iOS. Tests are written in Objective-C. GHUnit allows you to (a list of the important functionality):

  • Run tests, breakpoint and interact directly with the XCode Debugger
  • Run test in  parallel
  • View logging, stack traces and debugging information by test case
  • Run a specific test or the whole test suite

To install, see git url: https://github.com/gabriel/gh-unit#install-docset

 

Example:

 

#import <GHUnitIOS/GHUnit.h>

 

@interface ExampleTest : GHTestCase { }

@end

 

@implementation ExampleTest

 

- (void)testExample

{

// Do something..

GHTestLog(@”I’m doing something..”;

 

// .. and compare the result.

if ( […] )

{

GHTestLog(@”Test failed!”);

GHAssertTrue(NO, @”Error. Test failed!”);

}

GHTestLog(@”Test passed!”);

}

 

@end

 

.

 

KIF iOS – Dismiss Alert

How to dismiss UIAlertView with a button title? There is no assigned step that can be used to do it, so I spent some time before find how to do. The alert buttons’ accessibility label are the same as their titles.

So if you need to tap the alert in the image you need to execute the following step:

scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"OK"]]

 

 

Impara il Cinese con la prima App Italiana

logo-512x512-new

Sei un italiano e vuoi imparare il Cinese? Nel market Android trovi solo App in Inglese e nessuna in italiano? Allora sei capitato nella pagina giusta per te!

Oggi è stata rilasciata la nuova versione dell’App CiIta (Cinese per Italiani) con una grafica e una User Experience totalmente rinnovata.

Non sei ancora convinto? Scarica la versione di prova da Google Play Store.

Zaijian.

 

Random String Generator in ObjectC

Screen Shot 2013-03-05 at 4.34.58 PM

Here it is a way to generate a random string value in ObjectC.  In my example I generate a random name for creating a random email.

Function to generate a random string, it gets the string length as input:

NSString *letters = @”abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789″;

-(NSString *) genRandStringLength: (int) leng {
NSMutableString *randomString = [NSMutableString stringWithCapacity: leng];

for (int i=0; i<leng; i++)

{

[randomString appendFormat: @"%C", [letters characterAtIndex: arc4random() % [letters length]]];
}
return randomString;
}

And here how to create the email by using the output of genRandStringLength

 NSString *email  =  [[self genRandStringLength:10] stringByAppendingString:@”@doman.it”];

 

Selenium does not delete temp files after test exits

I discovered that the size of my /tmp folder was suddenly increasing and after a fast check, the folder was full of seleniumSsl* files. Checking around, I see that Selenium create temp files after TestCase fails, then so I patch it by adding a little piece of code just before server shutdown. Here it is (it is written in Python):

def remove_temp():
  for f in glob.glob( “/tmp/seleniumSsl*/*” ) :
    try:
      os.remove( f)
    except:
      pass
  [ os.rmdir( f ) for f in glob.glob("/tmp/seleniumSsl*" ) ]

 

[Linux Mint] Cannot get Video to display, only audio

linux-mint

How to fix it in VLC. Select from menu

“Tools > Preferences > Video button > Output: X11 video output (XBC)”.

It solved my problem.

Movies as code

Movies as code

The Green Mile

<?php
$cure = 3;
$john = 'alive';
$living = array(0 => 'good', 1 => 'bad');
$is_healthy = array(0 => 'yes', 1 => 'no');

while ($cure > 0 )
{

	$l = pick();

	if ( strcmp($living[$l], 'good') == 0 ) {
		$h = pick();
		if (strcmp($is_healthy[$h], 'no') == 0) {
		        $cure--;
		        echo "John takes care of the living";

		}
	}
}

//John dies
unset($john);

function pick() {
	return rand(0, 1);
}
?>

 

The Butterfly Effect

<script>
	$(".the").click(function () {
		$(".butterfly").fadeIn("slow");
	});
</script>

 

Finding Nemo

grep -r "Nemo" ./

 

The Last of the Mohicans

SELECT * FORM Mohican ORDER BY Desc LIMIT 1

Create a Cookie in Chrome

cookie2

Chrome has own “Inspect Developer bar”, but unfortunately it is not possible insert a cookie in fast way as it can be done by using FF. BTW there is an easy way to add one for a particular page following few steps.

  1. Open the url that you need add the cookie
  2. Type into the: javascript:document.cookie=”CookieName=CookieValue”. NOTE: If you copy and paste the row, it can be that the word javascript can be not written, if so, type it again.
Remember, the cookie is valid ONLY for the url you type at step 1.

Object-C Block Module

Se le funzioni diventano moooolto lunghe, per rendere il codice comprensibile, si può ricorrere ai blocchi.

Ecco la sintassi generica di un blocco:

return_type (^blockName)(var_type) = ^return_type (var_type varName)
{
    // ...
};

Mentre questo è un esempio specifico:

void (^resultCompare)(NSDictionary *) = ^void (NSDictionary *dataDictionary)
{
    // ...
}