Answers for "junit and testng"

4

java junit test

import org.junit.Assert;
import org.junit.Test;

public class Test {

    public static int square(int n) {
        return n * n;
    }

    @Test
    public void squareTest() {
        Assert.assertEquals(25, square(5));
        Assert.assertEquals(16, square(4));
        Assert.assertEquals(9, square(3));
        Assert.assertEquals(4, square(2));
        Assert.assertEquals(1, square(1));
    }
}
Posted by: Guest on October-23-2020
0

how to write a junit test case in java

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class MyTests {

    @Test
    public void multiplicationOfZeroIntegersShouldReturnZero() {
        MyClass tester = new MyClass(); // MyClass is tested

        // assert statements
        assertEquals(0, tester.multiply(10, 0), "10 x 0 must be 0");
        assertEquals(0, tester.multiply(0, 10), "0 x 10 must be 0");
        assertEquals(0, tester.multiply(0, 0), "0 x 0 must be 0");
    }
}
Posted by: Guest on July-14-2020
1

@test annotation in junit

# Used in JAVA
 public class Example {
    @Test
    public void method() {
       org.junit.Assert.assertTrue( new ArrayList().isEmpty() );
    }
 }
Posted by: Guest on February-04-2021
-1

difference between junit and testng

-Annotations;
JUnit  --> @Test, @BeforeClass, @AfterClass, @Before, @After, @Ignore
TestNG --> @Test, @BeforeTest, @BeforeClass, @BeforeSuite, @BeforeMethod, 
		   @AfterTest, @AfterClass, @AfterSuite, @AfterMethod
           
-Both are testing framework to help us running automation scripts.
-TestNG provide HTML report.
-TestNG has @DataProvider annotation same as Cucumber Scenario Outline for DDT
-Both We can do parallel testing, but in different way. In TestNG we use XML
runner. In JUnit we use Maven Surefire Plugins.
-TestNG support group test but JUNit doesn't support.
-TestNG and JUnit both of them have parameterized testing but TestNG 
parameterizedd test configuration is very easy to configure. There are two ways
to achieve it in TestNG;
@Parameters and TestNG xml file
@DataProvider
Posted by: Guest on December-07-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language