BAEL-639: Fixing failing test
This commit is contained in:
46
testng/src/test/java/baeldung/com/DependentTests.java
Normal file
46
testng/src/test/java/baeldung/com/DependentTests.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class DependentTests {
|
||||
|
||||
private String validEmail = "abc@qwe.com";
|
||||
private EmailValidator emailValidator;
|
||||
private LoginValidator loginValidator;
|
||||
|
||||
@BeforeClass
|
||||
public void setup() {
|
||||
emailValidator = new EmailValidator();
|
||||
loginValidator = new LoginValidator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmail_ifValid_thenTrue() {
|
||||
boolean valid = emailValidator.validate(validEmail);
|
||||
Assert.assertEquals(valid, true);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "givenEmail_ifValid_thenTrue" })
|
||||
public void givenValidEmail_whenLoggedIn_thenTrue() {
|
||||
boolean valid = loginValidator.validate();
|
||||
Assert.assertEquals(valid, true);
|
||||
}
|
||||
}
|
||||
|
||||
class EmailValidator {
|
||||
|
||||
boolean validate(String validEmail) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class LoginValidator {
|
||||
|
||||
boolean validate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class ParametrizedTestNGTest {
|
||||
|
||||
@Test
|
||||
@Parameters({ "name", "expectedResult" })
|
||||
public void givenNumber_ifPrime_thenCorrect(String name, boolean expectedResult) {
|
||||
Assert.assertEquals(expectedResult, name.length() > 0);
|
||||
}
|
||||
|
||||
@DataProvider(name = "test1")
|
||||
public static Object[][] primeNumbers() {
|
||||
return new Object[][] { { "Peter", true }, { "Sam", true }, { "Tim", true }, { "Lucy", true } };
|
||||
}
|
||||
|
||||
@Test(dataProvider = "test1")
|
||||
public void givenNumber_whenPrime_thenCorrect(String name, boolean expectedResult) {
|
||||
Assert.assertEquals(expectedResult, name.length() > 0);
|
||||
}
|
||||
|
||||
@Test(dataProvider = "myDataProvider")
|
||||
public void parameterCheckTest(User user) {
|
||||
Assert.assertEquals("sam", user.getName());
|
||||
Assert.assertEquals(12, user.getAge());
|
||||
}
|
||||
|
||||
@DataProvider(name = "myDataProvider")
|
||||
public Object[][] parameterProvider() {
|
||||
User usr = new User();
|
||||
usr.setName("sam");
|
||||
usr.setAge(12);
|
||||
return new Object[][] { { usr } };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class User {
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
}
|
||||
11
testng/src/test/java/baeldung/com/RegistrationTest.java
Normal file
11
testng/src/test/java/baeldung/com/RegistrationTest.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class RegistrationTest {
|
||||
|
||||
@Test
|
||||
public void givenEmail_ifValid_thenCorrect() {
|
||||
|
||||
}
|
||||
}
|
||||
12
testng/src/test/java/baeldung/com/SignInTest.java
Normal file
12
testng/src/test/java/baeldung/com/SignInTest.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class SignInTest {
|
||||
|
||||
@Test
|
||||
public void givenUsername_ifValid_thenCorrect() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
95
testng/src/test/java/baeldung/com/SummationServiceTest.java
Normal file
95
testng/src/test/java/baeldung/com/SummationServiceTest.java
Normal file
@@ -0,0 +1,95 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.TestNG;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SummationServiceTest extends TestNG {
|
||||
|
||||
private List<Integer> numbers;
|
||||
|
||||
private int testCount = 0;
|
||||
|
||||
@BeforeClass
|
||||
public void initialize() {
|
||||
numbers = new ArrayList<>();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
numbers = null;
|
||||
}
|
||||
|
||||
@BeforeSuite(groups = "regression")
|
||||
public void runBeforeRegressionSuite() {
|
||||
numbers = new ArrayList<>();
|
||||
numbers.add(-11);
|
||||
numbers.add(2);
|
||||
}
|
||||
|
||||
@AfterSuite(groups = "regression")
|
||||
public void runAfterRegressionSuite() {
|
||||
numbers = null;
|
||||
}
|
||||
|
||||
@BeforeGroups("negative_tests")
|
||||
public void runBeforeEachNegativeGroup() {
|
||||
numbers.clear();
|
||||
}
|
||||
|
||||
@BeforeGroups("regression")
|
||||
public void runBeforeEachRegressionGroup() {
|
||||
numbers.add(-11);
|
||||
numbers.add(2);
|
||||
}
|
||||
|
||||
@BeforeGroups("positive_tests")
|
||||
public void runBeforeEachPositiveGroup() {
|
||||
numbers.add(1);
|
||||
numbers.add(2);
|
||||
numbers.add(3);
|
||||
}
|
||||
|
||||
@AfterGroups("positive_tests,regression,negative_tests")
|
||||
public void runAfterEachGroup() {
|
||||
numbers.clear();
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void runBeforeEachTest() {
|
||||
testCount++;
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void runAfterEachTest() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test(groups = "positive_tests", enabled = false)
|
||||
public void givenNumbers_sumEquals_thenCorrect() {
|
||||
int sum = numbers.stream().reduce(0, Integer::sum);
|
||||
Assert.assertEquals(sum, 6);
|
||||
}
|
||||
|
||||
@Test(groups = "negative_tests")
|
||||
public void givenEmptyList_sumEqualsZero_thenCorrect() {
|
||||
int sum = numbers.stream().reduce(0, Integer::sum);
|
||||
Assert.assertEquals(0, sum);
|
||||
}
|
||||
|
||||
@Test(groups = "regression")
|
||||
public void givenNegativeNumber_sumLessthanZero_thenCorrect() {
|
||||
int sum = numbers.stream().reduce(0, Integer::sum);
|
||||
Assert.assertTrue(sum < 0);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = ArithmeticException.class)
|
||||
public void givenNumber_whenThrowsException_thenCorrect() {
|
||||
int i = 1 / 0;
|
||||
}
|
||||
|
||||
}
|
||||
44
testng/src/test/java/baeldung/com/TestGroup.java
Normal file
44
testng/src/test/java/baeldung/com/TestGroup.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class TestGroup {
|
||||
|
||||
@BeforeGroups("database")
|
||||
public void setupDB() {
|
||||
System.out.println("setupDB()");
|
||||
}
|
||||
|
||||
@AfterGroups("database")
|
||||
public void cleanDB() {
|
||||
System.out.println("cleanDB()");
|
||||
}
|
||||
|
||||
@Test(groups= "selenium-test")
|
||||
public void runSelenium() {
|
||||
System.out.println("runSelenium()");
|
||||
}
|
||||
|
||||
@Test(groups= "selenium-test")
|
||||
public void runSelenium1() {
|
||||
System.out.println("runSelenium()1");
|
||||
}
|
||||
|
||||
@Test(groups = "database")
|
||||
public void testConnectOracle() {
|
||||
System.out.println("testConnectOracle()");
|
||||
}
|
||||
|
||||
@Test(groups = "database")
|
||||
public void testConnectMsSQL() {
|
||||
System.out.println("testConnectMsSQL");
|
||||
}
|
||||
|
||||
@Test(dependsOnGroups = {"database","selenium-test"})
|
||||
public void runFinal() {
|
||||
System.out.println("runFinal");
|
||||
}
|
||||
|
||||
}
|
||||
11
testng/src/test/java/baeldung/com/TimeOutTest.java
Normal file
11
testng/src/test/java/baeldung/com/TimeOutTest.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package baeldung.com;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class TimeOutTest {
|
||||
|
||||
@Test(timeOut = 1000, enabled = false)
|
||||
public void givenExecution_takeMoreTime_thenFail() {
|
||||
while (true) ;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user