Important unit test

xiaoxiao2021-03-06  76

The following code

Import java.util.date;

Import junit.framework.testcase;

Public Class TestTest Extends Testcase {

Public static void main (string [] args) {junit.swingui.teestrunner.run (payrolltest.class);}

Public Testltest (String Name) {super (name);

Public void testdate ()

{

Date lastday = new date (2004, 2, 30);

Test T = New Test ();

Asserttrue (t.islastdayofmonth);

}

}

Class test {

Final long onEDay = 24 * 60 * 60 * 1000;

Boolean islastdayOfmonth (Date Date) {

INT m1 = date.getMonth (); int m2 = (new date (Date.getTime () OneDay)). getMonth (); Return (m1! = m2);

}

}

This unit test did not pass, and later she knew the reason, the month of Java.util.date class is from 0 to 11.3 months in April, and the year must be reduced by 1900. Therefore, the unit test cannot be passed, and how important the unit test can be seen from here. If there is no unit test, I know that I may not find this problem.

转载请注明原文地址:https://www.9cbs.com/read-121044.html

New Post(0)