0% found this document useful (0 votes)
60 views2 pages

Junit Testibg

Unit tests ensure code works as intended and validates functionality after changes. JUnit is a test framework that uses annotations to identify test methods, which should not depend on other tests. To write a JUnit test, annotate a method with @Test and use assertion methods to check expected versus actual results. JUnit can be run in Eclipse or with JUnitCore and is downloaded from its website as a JAR file added to the classpath.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

Junit Testibg

Unit tests ensure code works as intended and validates functionality after changes. JUnit is a test framework that uses annotations to identify test methods, which should not depend on other tests. To write a JUnit test, annotate a method with @Test and use assertion methods to check expected versus actual results. JUnit can be run in Eclipse or with JUnitCore and is downloaded from its website as a JAR file added to the classpath.

Uploaded by

govindbirajdar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.1.

Unit Testing
A unit test is a piece of code written by a developer that executes a specific functionality in the code under test. Unit tests ensure that code is working as intended and validate that this is still the case after code changes.

1.2. Unit Testing with JUnit


JUnit 4.x is a test framework which uses annotations to identify methods that are tests. JUnit assumes that all test methods can be executed in an arbitrary order. Therefore tests should not depend on other tests. To write a test with JUnit
y y

Annotate a method with @org.junit.Test Use a method provided by JUnit to check the expected result of the code execution versus the actual result

You can use Eclipse or the class "org.junit.runner.JUnitCore" to run the test.

2. Installation of JUnit
If you use Eclipse you can use the integrated JUnit in Eclipse for your testing. If you want to control the used JUnit library explicitly, download JUnit4.x.jar from the JUnit website at http://www.junit.org/ . The download contains the "junit-4.*.jar" which is the JUnit library. Add this library to your Java project and add it to the classpath.

package com; public class testingDemo { int c; public int add(int a,int b) { return(c=a*b); } }

Test Class package com;

import static org.junit.Assert.*;

import org.junit.Test;

public class testingDemoTest {

@Test public void testAdd() { testingDemo tester= new testingDemo(); fail("problem is there testing failed Debug it....."); assertEquals("Result", 3, tester.add(10, 3));

You might also like