unit testing

35
Unit Testing 이이이 [email protected] [email protected] www.facebook.com/gyuwon.yi

Upload: gyuwon-yi

Post on 28-Jul-2015

757 views

Category:

Software


4 download

TRANSCRIPT

“Know the rules well, so you can break them effectively.”- Dalai Lama XIV

Automated Testing

Software Regression

“A software bug which makes a feature stop functioning as intended after a certain event”

- Wikipedia

R1 R2 R3 R4

SoftwareFeatures

Costs

Manual(Quality Assurance) Automated

>

Reliability

Manual(Quality Assurance) Automated

<

Arrange

ActAssert

Cleanup

DEMOAutomated UI Testing

Continuous Integration

“Many, including me, consider that CI without testing is not CI at all.”

- The Architecture Journal, January 2008 by Munjal Budhabhatti

Continuous Build

Continuous Integration

Automated Testing

Unit Tests

Horizontal Separation

Layer D

Layer C

Layer B

Layer A

Functional Testing(Vertical Separation)

Syste

m U

nd

er Te

st

Layer D

Layer C

Layer B

Layer A Syste

m U

nd

er Te

stLayer D

Layer C

Layer B

Layer A Syste

m U

nd

er Te

st

Layer D

Layer C

Layer B

Layer A

Function 1 Function 2 Function 3

*Integration Testing

Layer D

Layer C

Layer B

Layer A Syste

m U

nd

er Te

stSystem Under Test

System Under Test

Unit Testing

Layer D

Layer C

Layer B

Layer A System Under Test

System Under Test

System Under Test

System Under Test

Unit Testing

• Fast• Reliable• Isolate failures

Test Doubles

Layer D

Layer C

Test Double for Layer B

Layer A

System Under Test

Inversion of Control

“Don't call us, we'll call you.”

Dependency Inversion

A Layer C depends on a Layer B

A Layer C creates a Layer BA Layer C requests a Layer B

Constructor Injection

public class LayerC

{

private LayerB _layerB;

public LayerC()

{

_layerB = new LayerB();

}

}

public class LayerC

{

private LayerB _layerB;

public LayerC(LayerB layerB)

{

_layerB = layerB;

}

}

<< created >>

<< injected >>

*Interface

public interface ILayerB{}

public class LayerB : ILayerB{}

public class LayerC{ private ILayerB _layerB;

public LayerC(ILayerB layerB) { _layerB = layerB; }}

Test Double

The replacement of a real depended-on componentfor testing purposes

Test Doubles

Dummy

Stubs

Spies

Mocks

Fake

Passed but never used

Provide canned answers

Record information

Verify expectationsHave working

implementations but not suitable for production

DEMOStubs and Mocks

Myth Busting for

Test-Driven Development

Automated testing

TDD

Automated testing with high coverage

TDD

Writing the tests first

TDD

?

Test-Driven Development

Test-Driven Development

Test

Development

TESTS

MAKETH

CODE

Red

GreenRefactor

Write production code

If the test fails

If all tests

succeed

Clean up code

Write a test

yes

yes

no

no

repeat

DEMOTest-Driven Development