Frameworks:
JUnit: it is
software which provides some facilities through annotations which make the
testing job easier as it is making some (testing) job more easy people
generally call it as JUnit Framework.
Configuring JUnit into eclipse:
Right click on project select Properties.
Click on Java Build Path
Click on Add Library
Click on JUnit then click on Next
From the drop down list box select
JUnit4
Click in finish.
Note:
if the project is newly created then configure the selenium web driver also to
your project, the process of configuring selenium is mentioned in the above
pages.
Note2:
We no need
to have main() method in our class because TestNG is going to take care about
it.
It is new and famous framework having more no of
annotations.
Order of Execution is based on the annotations but
not in the order in which we have written the code.
More powerful reports will be generated compared
to JUnit.
JUnit and TestNG both are almost same difference
is at annotations.
In JUnit @BeforeClass and @AfterClass annotation’s
methods must be static but in TestNG no need be static methods.
In JUnit @Before and @After annotations are
available but in JUnit we have @BeforeMethod and @AfterMethod
Ignoring or skipping test cases while executing:
In JUnit: we need to write @Ignore before @Test to
skip that particular test.
E
g.:
@Ignore
@Test //test
case
public void
balanceenqurytest() {
System.out.println("logic
for balance enqury is here....");
}
In TestNG: to skip any test, in TestNG we need to
write (enabled=false) along with @Test
E g.:
@Test(enabled=false)
public void
withdraw() {
System.out.println("logic
for withdraw is here....");
}
Demonstration of JUnit framework
package pack;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import
org.testng.annotations.AfterMethod;
import
org.testng.annotations.BeforeMethod;
public class junit {
package pack11;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class junit {
public static void
invokeapplicationtest() {
System.out.println("application
invoking logic is here");
}
@AfterClass
public static void
closeapplicationtest() {
System.out.println("application
closing logic is here");
}
@Before
public void
login() {
System.out.println("logic
for login is here");
}
@After
public void
logout() {
System.out.println("logic
for logout is here...");
}
@Test
public void
withdraw() {
System.out.println("logic
for withdraw is here....");
}
@Test //test
case
public void
balanceenqurytest() {
System.out.println("logic
for balance enqury is here....");
}
}
Note:
We no need
to have main() method in our class because JUnit is going to take care about
it.
It is old and famous framework having more no of
annotations.
Order of Execution is based on the annotations but
not in the order in which we have written the code
No comments:
Post a Comment