Unit testing
Transcript of Unit testing
Unit Testing이규원
www.facebook.com/gyuwon.yi
Software Regression
“A software bug which makes a feature stop functioning as intended after a certain event”
- Wikipedia
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
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
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 Doubles
Dummy
Stubs
Spies
Mocks
Fake
Passed but never used
Provide canned answers
Record information
Verify expectationsHave working
implementations but not suitable for production
Write production code
If the test fails
If all tests
succeed
Clean up code
Write a test
yes
yes
no
no
repeat