Perl-unit test

Source: Internet
Author: User

TDD-test-driven

Red-> green-> refactoring

 

Code

  #  IntroductionSource codeDirectory  
Use Lib " /Sdbdata/develop/src/lib/ " ;
# Introduce the package to be tested
Use Log4p;

# Number of test cases
Use Test :: More Tests => 8 ;

# Or alternately, if we don't know how well:
# Use test: More QW (no_plan );

# Test Initialization
# Check that our module compiles and can be "use" D.
Begin {use_ OK ( ' Perlnet: testme ' );}

# Check our module can be required. Very similar test to that above.
Require_ OK ( ' Perlnet: testme ' );

# There are a number of ways to generate the "OK" tests. These are:
# OK: first argument is true, second argument is name of test.
# Is: first argument equals (EQ) second argument, third argument is name of test.
# Isnt: first argument does not equal (NE) the Second, Third is name of test
# Like: first argument matches Regexp in second, third is name of test
# Unlike: first argument does not match Regexp, third is name of test
# Cmp_ OK: Compares first and third argument with comparison in second. Forth is test name.

OK (( 1 + 1 ) = 2 , " Basic addition is working " );
Is ( 2 - 1 , 1 , " Basic Subtraction is working " );
Isnt ( 2 * 2 , 5 , " Basic multiplication doesn' t fail " );
Like ( " Perlnet is great " , Qr / Perlnet / I , " Finding perlnet in a string " );
Unlike ( " Perlnet is great " , Qr / Pythonnet / I , " Not finding pythonnet in a string " );
Cmp_ OK ( $ This , ' = ' , $ That , " Comparing $ this and $ that with integer = " );

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.