Andate A La Concha De Tu Madre

Páginas: 3 (612 palabras) Publicado: 3 de julio de 2012
Test the untestable
Johan Haleby and Jan Kronquist www.powermock.org

Certified Java Professionals
1

Audience survey
Writing unit tests? Using mock framework? Using EasyMock? Frustrated withcurrent limitations?

Certified Java Professionals
2

Automated + isolated testing
Mock A A TestCase Code Under Test Mock B B

Certified Java Professionals
3

Mock objects and stubsSimulated objects that mimic behavior of real objects Stubs provide canned replies Mocks verify expectations

Certified Java Professionals
4

EasyMock
// Create a mock SomeInterface mock =createMock(SomeInterface.class); // Record behavior expect(mock.doStuff("argument")).andReturn("returnValue"); // Replay behavior replay(mock); // Executing the code we want to test assertEquals("returnValue",test.perform()); // Verify behavior verify(mock);

Certified Java Professionals
5

Traditional assumptions
Testable = good design Testable = easy to understand Testable = limitations

CertifiedJava Professionals
6

Problem - Static methods
Not possible to mock Still 3rd party libraries that use them
Eclipse, Java ME

Certified Java Professionals
7

Problem - Static initializersYou cannot unit test a class with evil static initializer
public class EvilStaticInitializer { static { System.loadLibrary(“evil.dll”); } }

Certified Java Professionals
8

Problem - Final class/ method
Final methods cannot be mocked Why use final?
Ensure that your classes are not misused Correct object construction

Examples: Wicket, Apache Mina

Certified Java Professionals
9 Problem - Private methods/state
Invocation is hard Mocking not possible State access not possible Private is used to enforce encapsulation

Certified Java Professionals
10

Problem - Using newCode not designed for testing Not everything needs to be injected
File file = new File(fileName); if (file.exists()) { doStuff(); }

Certified Java Professionals
11

Traditional solutions
Better...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • La Concha De Tu Madre
  • la concha de tu madre
  • La concha de tu madre
  • la concha de tu madre
  • La concha de tu madre
  • La Concha De Tu Madre
  • La concha su madre
  • La concha de tu madre

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS