Test Driven Development and Testing Private Methods using

  • Slides: 24
Download presentation
Test Driven Development and Testing Private Methods using JUnit By: Taylor Helsper

Test Driven Development and Testing Private Methods using JUnit By: Taylor Helsper

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private Methods Example � Conclusion

Introduction � What is this lecture? ◦ Part of a CSE 4000 Independent Study

Introduction � What is this lecture? ◦ Part of a CSE 4000 Independent Study Course ◦ “Practical Issues in Software Engineering” � What’s the point? ◦ To provide practical information to students in Software Engineering topics Note: The products discussed in this presentation are examples used for teaching purposes and are not endorsements of the products.

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private Methods Example � Conclusion

Test Driven Development � What is it? ◦ Development/Testing process where tests are generated

Test Driven Development � What is it? ◦ Development/Testing process where tests are generated before the development ◦ Development is completed based on the tests

Test Driven Development � Why is it useful? ◦ Distinct Steps ◦ Good Metrics

Test Driven Development � Why is it useful? ◦ Distinct Steps ◦ Good Metrics ◦ Ensures Completion Based on Requirements/Design

Test Driven Development � Why is it useful? ◦ Only necessary features are implemented

Test Driven Development � Why is it useful? ◦ Only necessary features are implemented ◦ Short Development Lifecycle ◦ Easy to Accommodate Changes

Test Driven Development � Steps ◦ Write tests based on design / requirements ◦

Test Driven Development � Steps ◦ Write tests based on design / requirements ◦ Write code ◦ Run tests ◦ Repeat until all tests pass

Test Driven Development http: //en. wikipedia. org/wiki/Test-driven_development

Test Driven Development http: //en. wikipedia. org/wiki/Test-driven_development

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private Methods Example � Conclusion

JUnit � What is it? ◦ JUnit is a testing framework for Java ◦

JUnit � What is it? ◦ JUnit is a testing framework for Java ◦ It allows programmers to write test cases for Java classes

JUnit � Why use it? ◦ Repeatability ◦ Metrics / Measurement ◦ Easy Integration

JUnit � Why use it? ◦ Repeatability ◦ Metrics / Measurement ◦ Easy Integration

JUnit Examples �A JUnit Test Case

JUnit Examples �A JUnit Test Case

JUnit Examples � JUnit Before/ After

JUnit Examples � JUnit Before/ After

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private

Outline � Introduction � Test Driven Development � JUnit � Testing � TDD Private Methods Example � Conclusion

Testing Private Methods � Why? ◦ Better Tests ◦ Higher Probability Errors are Found

Testing Private Methods � Why? ◦ Better Tests ◦ Higher Probability Errors are Found ◦ Meet Regulations �Testing Standards �Code Coverage

Testing Private Methods � How? ◦ Use Reflection ◦ Java classes know info about

Testing Private Methods � How? ◦ Use Reflection ◦ Java classes know info about themselves �Functions �Variables

Testing Private Methods � Java Example ◦ Get Private Access

Testing Private Methods � Java Example ◦ Get Private Access

Testing Private Methods � Java Example ◦ Test Private Method

Testing Private Methods � Java Example ◦ Test Private Method

Outline � Introduction � Test Driven Development � JUnit � TDD Example � Conclusion

Outline � Introduction � Test Driven Development � JUnit � TDD Example � Conclusion

TDD Example � Math Class for a Calculator Program � Steps ◦ Generate Tests

TDD Example � Math Class for a Calculator Program � Steps ◦ Generate Tests ◦ Code ◦ Run Tests ◦ Repeat

Conclusion � Test Driven Development is important to understand � TDD is useful in

Conclusion � Test Driven Development is important to understand � TDD is useful in many circumstances ◦ Saves Money ◦ Is Agile ◦ Offers Good Metrics

References � Junit - http: //www. junit. org/ � Netbeans – http: //netbeans. org/

References � Junit - http: //www. junit. org/ � Netbeans – http: //netbeans. org/ � � � JUnit Examples http: //junit. sourceforge. net/doc/cookbook. htm MSU Classes and work experience Stack Overflow for Reflection Code http: //stackoverflow. com/questions/34571/whats-the-best-way-ofunit-testing-private-methods Real’s How To for Reflection Code http: //www. rgagnon. com/javadetails/java-0031. html “Subverting Java Access Protection for Unit Testing” by Ross Burton. 11/12/2003. onjava. com.

Questions?

Questions?