Вы находитесь на странице: 1из 9

Javenue

Java

2
January
2006

JUnit (Test Case)


Posted in: Java open-source , , Java technologies, J2SE |
English version of this article you can find here.
.
. ?
.
? JUnit,
.
JUnit Framework, ?
Java . -
:
public class MathFunc {
private int variable;
public MathFunc() {
variable = 0;
}
public MathFunc(int var) {
variable = var;
}
public int getVariable() {
return variable;
}
public void setVariable(int variable) {
this.variable = variable;
}
public long factorial() {
long result = 1;
if (variable > 1) {
for (int i=1; i<=variable; i++)
result = result*i;
}
return result;
}
public long plus(int var) {
long result = variable + var;
return result;

}
}

junit.framework.TestCase.
, (String)
. , ? ,
:
public class TestClass extends TestCase {
public TestClass(String testName) {
super(testName);
}
public void testFactorialNull() {
MathFunc math = new MathFunc();
assertTrue(math.factorial() == 1);
}
public void testFactorialPositive() {
MathFunc math = new MathFunc(5);
assertTrue(math.factorial() == 120);
}
public void testPlus() {
MathFunc math = new MathFunc(45);
assertTrue(math.plus(123) == 168);
}
}

assertTrue , .
, - assertEquals, assertFalse, assertNull, assertNotNull, assertSame.
, , TestSuite
addTest. , TestRunner.
junit.textui.TestRunner ( junit.swingui.TestRunner, junit.awtui.TestRunner). main :
public static void main(String[] args) {
TestRunner runner = new TestRunner();
TestSuite suite = new TestSuite();
suite.addTest(new TestClass(testFactorialNull));
suite.addTest(new TestClass(testFactorialPositive));
suite.addTest(new TestClass(testPlus));
runner.doRun(suite);
}

:
Time: 0,02
OK (3 tests)

, setUp tearDown.

TestCases,
.
JUnit . , JUnit Framework
.

24 Comments
RSS feed for comments on this post. TrackBack URI

Vitali K
February 24, 2006 #
!
? - assert
.
-
( ) ? ? !
hudson
September 3, 2006 #
! jUnit. junit
framework web selenium.
- ?
Bishop
September 21, 2006 #
Good article. But Id like to get more information about such methods as: setUp() and tearDown() in
examples.Tnx
hudson
November 7, 2006 #
:). ,
, -
jar . IDE .
? dmitry(dot)bykadorov(at)gmail.com

November 26, 2006 #
-. NUnit. ? , ?
, ) ( ?)

{
[Test]
?()

{
Assert(myClass.Mul(2,2),4);
}
}
:) - JUNIT?
DiVor
December 5, 2006 #
, (junit 4.0 + idea 6.x)
Denis
March 2, 2007 #
- , 10 JUnit.
:
1)
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new TestClass(testFactorialNull));
suite.addTest(new TestClass(testFactorialPositive));
suite.addTest(new TestClass(testPlus));
return suite;
}
2) TestClass test, JUnit
( ? ?
, )
PVoLan
March 4, 2007 #
- main JUnit!
c0nst
March 4, 2007 #
2PVoLan: , . IDE
.
2Denis: : Java 1.5 .
JUnit 1.5 ,
, . , 1.4.2 . ,
?
slavik112211
August 6, 2008 #
:
http://www.linux.ie/articles/tutorials/junit.php
? !
:)


August 14, 2008 #
, ! ! , !
Agent
September 10, 2008 #
!
JUnit.
? :
:
?
public interface Triangle
{
int getLen1();
int getLen2();
int getLen3();
}
3 , .
:
public final class TriangleProvider
{
public static Triangle getTriangle()
{

}
}
: junit , getTriangle ,
.
!
STARfish
September 11, 2008 #
2 Agent.
? ndex ?:))))
Mihey
June 11, 2009 #

Giraffe

December 2, 2009 #
, hudson.
JUnit - IDE?
hudson
December 27, 2009 #
Giraffe, . ? CLASSPATH ))
.
Don
March 19, 2010 #
, ?
c0nst
March 19, 2010 #
@Don:
, - (
, ? ).
, .
Don
March 19, 2010 #
, , . , , ..
. CaseTest,
? @Test, ,
TestCase.
, JUnit4?
GX3P
July 19, 2010 #
,
, , . JUnit? ,
MathFunc math = new MathFunc(45);
assertTrue(math.plus(123) == 168);
, ?
. ?
.
.
,
Taper
August 27, 2010 #
To GX3P:

,
-
JUnit
, : 45 + 123 = 168.
: , -
( ), ,
- JUnit-.
, ,
, .
,
( ),

, SDK
. .
mike
March 20, 2011 #
to hudson
jar.
- junit****.jar
java/lib/ext
.
, *.class CLASSPATH.
jar class-path .

http://download.oracle.com/javase/1.4.2/docs/tooldocs/findingclasses.html
SunHere
August 15, 2011 #
, , , unit
?
, ?
chinaexp
August 16, 2011 #
http://chinaexp.ru -!

Leave a comment
XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em>
<i> <strike> <strong> <pre>

Name *
Mail (will not be published) *
Website

Submit Comment

Blog
English
Archives
About

Search

Web

javenue.info

Google

Categories
Java GUI, Swing, AWT, SWT
Java open-source
Java technologies (translated)
Java technologies, J2SE
Java Web Design, J2EE
Project Management

XML, XPath


, SQL, Oracle
.
, SEO
(uncategorized)


Java -
www.quizful.net

Powered by WordPress, Design by Aph1na


RSS: Posts, Comments