Skip to content

Instantly share code, notes, and snippets.

@solanoize
Created November 18, 2024 12:53
Show Gist options
  • Select an option

  • Save solanoize/3e975fb0ac38b939d7aefe2be26d51a2 to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/3e975fb0ac38b939d7aefe2be26d51a2 to your computer and use it in GitHub Desktop.

Kode test:

import static org.testng.AssertJUnit.assertEquals;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class CalculatorTest {

  @Test(dependsOnMethods = {"subtractTest", "multiplyTest"}, priority = -2)
  public void addTest() {
	  int a = 1;
	  int b = 2;
	  int actual = Calculator.add(a, b);
	  int expected = 3;
	  System.out.println("Menjalankan addTest");
	  assertEquals(actual, expected);
  }

  @Test(priority = -1)
  public void subtractTest() {
	  int a = 1000;
	  int b = 100;
	  int actual = Calculator.subtract(a, b);
	  int expected = 900;
	  System.out.println("Menjalankan subtractTest");
	  assertEquals(actual, expected);
  }
  
  @Test(priority = -4)
  public void multiplyTest() {
	  int a = 10;
	  int b = 4;
	  int actual = Calculator.multiply(a, b);
	  int expected = 40;
	  System.out.println("Menjalankan multiplyTest");
	  assertEquals(actual, expected);
  }
  
  @Test(dependsOnMethods = {"subtractTest"}, priority = -3)
  public void divideTest() {
	  System.out.println("Menjalankan divideTest");
	  assertEquals(true, true);
  }
  
  @BeforeMethod
  public void beforeMethod() {
	  System.out.println("Menjalankan before method");
  }
  
  @AfterMethod
  public void afterMethod() {
	  System.out.println("Menjalankan after method");
  }
  
  @BeforeClass
  public void beforeClass() {
	  System.out.println("Menjalankan before class");
  }
  
  @AfterClass
  public void afterClass() {
	  System.out.println("Menjalankan after class");
  }
  
  @BeforeTest
  public void beforeTest() {
	  System.out.println("Menjalankan before test");
  }
  
  @AfterTest
  public void afterTest() {
	  System.out.println("Menjalankan after test");
  }
  
  @BeforeSuite
  public void beforeSuite() {
	  System.out.println("Menjalankan before suite");
  }
  
  @AfterSuite
  public void afterSuite() {
	  System.out.println("Menjalankan after suite");
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment