18

Click here to load reader

Software Engineering

Embed Size (px)

Citation preview

Page 1: Software Engineering

Software Engineering

Robbie Clutton

Page 2: Software Engineering

readme.txt

• Started City University 2001• Did industrial placement with Lloyds TSB

2003-2004– Coding Cobol 74, editing code written before I was

born!

• Graduated Software Engineering BEng 2005• Joined BT graduate scheme

Page 3: Software Engineering

readme.txt

• SDK to access BT Web Services in .NET C#• Worked with customers to build prototypes

against BT Web Services• RESTful website using Ruby on Rails• SIP Application Server to support BT Web

Services using Java• IVR Web Service using SIP A/S using Java• Website using PHP

Page 4: Software Engineering

Unit Testing

• Tests a unit of code (e.g. a method)• Doing the simplest thing that could possibly

work• Living documentation• Allows refactoring• Assert upon the correctness of the application

Page 5: Software Engineering

@Testpublic void testHelloWorld(){

// setupHelloWorld helloWorld = new HelloWorld();// actString result = helloWorld.sayHello();// assertassertEquals("Hello", result);

}

package com.iclutton.seday;

public class HelloWorld {

public String sayHello() {return language.sayHello();

}

}

Page 6: Software Engineering

Interfaces

• Benefits unit testing• Makes code cleaner

Page 7: Software Engineering

package com.iclutton.seday.language;public interface Language { String sayHello();}

package com.iclutton.seday.language;

public class English implements Language{

@Overridepublic String sayHello() {

return "Hello";}

}

package com.iclutton.seday.language;

public class French implements Language{

@Overridepublic String sayHello(){

return "Bonjour";}

}

Page 8: Software Engineering

Mocking

• Useful when you want to ‘mock’ out external dependencies– Databases– Web services– Etc

• Useful for simulating error conditions and handling

Page 9: Software Engineering

@Testpublic void testHelloWorldWithMock(){

// setupEnglish english = mock(English.class);when(english.sayHello()).thenReturn("Alright");HelloWorld helloWorld = new HelloWorld();helloWorld.setLanguage(english);// actString result = helloWorld.sayHello();// assertassertEquals("Alright", result);verify(english).sayHello();

}

@Test(expected=IllegalStateException.class)public void testHelloWorldWithMockException(){

// setupEnglish english = mock(English.class);when(english.sayHello()).thenThrow(new RuntimeException());HelloWorld helloWorld = new HelloWorld();helloWorld.setLanguage(english);// acthelloWorld.sayHello();// assert - see exception annotation

}

Page 10: Software Engineering

Dependency Injection

• We’ve already seen dependency injection• Now let’s look at Spring, which supports– Reduces complexities of using interfaces– Great way to configure applications– Promotes the use of singletons– Improves testability

Page 11: Software Engineering

<bean id="language" class="com.iclutton.seday.language.English"/>

<bean id="hello" class="com.iclutton.seday.HelloWorld"><property name="language" ref="language"/>

</bean>

@Testpublic void testSpring(){

// setupApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");HelloWorld helloWorld = (HelloWorld)applicationContext.getBean("hello");// actString result = helloWorld.sayHello();// assertassertEquals("Hello", result);

}

Page 12: Software Engineering

Build Scripts

• Manual processes are more error prone• Build scripts bring consistency and automation• There are many varieties– Ant (Java)– nAnt (.NET)– Make (C/C++)– Rake (Ruby)– etc

Page 13: Software Engineering

Property Driven Builds

• Useful when more that one person becomes involved

• Or deploying to different environments

Page 14: Software Engineering

Source Control

Page 15: Software Engineering

Automating the Build

• Continuous Integration

Page 16: Software Engineering

Logging

• Until you support an application you’ve built you will never know the value of logging

Page 17: Software Engineering

# Root categorylog4j.rootLogger=DEBUG, stdoutlog4j.logger.com.iclutton.seday=DEBUG

# CONSOLElog4j.appender.stdout.Threshold=DEBUGlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayoutlog4j.appender.stdout.layout.ConversionPattern=%d %X{stackname}[%t] %-5p [%C{1}.%M() %L] - %m%n

2008-11-18 18:06:39,953 [main] DEBUG [AbstractAutowireCapableBeanFactory$1.run() 411] - Finished creating instance of bean 'hello'2008-11-18 18:06:39,953 [main] DEBUG [AbstractApplicationContext.publishEvent() 273] - Publishing event in context [org.springframework.context.support.ClassPathXmlApplicationContext@1e845c2]: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.ClassPathXmlApplicationContext@1e845c2: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1e845c2]; startup date [Tue Nov 18 18:06:39 GMT 2008]; root of context hierarchy]2008-11-18 18:06:39,953 [main] DEBUG [AbstractBeanFactory.doGetBean() 214] - Returning cached instance of singleton bean 'hello'

Page 18: Software Engineering

Q&A