Skip to content

Commit

Permalink
some test samples added
Browse files Browse the repository at this point in the history
  • Loading branch information
sody committed Jun 6, 2011
1 parent a2b429b commit a994693
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.Random;

/**
* @author Ivan Khalopik
* @since 8.0
*/
public class AdditionalTest extends Assert {
private Random generator;

@BeforeClass
public void setUpGenerator() {
generator = new Random();
}

@Test(successPercentage = 50, invocationCount = 100)
public void testAdditionalFunctionality() {
if (generator.nextBoolean()) {
fail();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
package com.example;

import org.testng.Assert;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

Expand All @@ -34,14 +31,14 @@ public class LocaleUtilsTest extends Assert {

@DataProvider
public Object[][] parseLocaleData() {
return new Object[][]{
{null, null},
{"", LocaleUtils.ROOT_LOCALE},
{"en", Locale.ENGLISH},
{"en_US", Locale.US},
{"en_GB", Locale.UK},
{"ru", new Locale("ru")},
{"ru_RU_xxx", new Locale("ru", "RU", "xxx")},
return new Object[][] {
{ null, null },
{ "", LocaleUtils.ROOT_LOCALE },
{ "en", Locale.ENGLISH },
{ "en_US", Locale.US },
{ "en_GB", Locale.UK },
{ "ru", new Locale("ru") },
{ "ru_RU_xxx", new Locale("ru", "RU", "xxx") },
};
}

Expand All @@ -51,20 +48,7 @@ public void testParseLocale(String locale, Locale expected) {
assertEquals(actual, expected);
}

@DataProvider(name = "getCandidateLocalesData", parallel = true)
public Object[][] getCandidateLocalesData() {
return new Object[][]{
{null, Arrays.asList(LocaleUtils.ROOT_LOCALE)},
{LocaleUtils.ROOT_LOCALE, Arrays.asList(LocaleUtils.ROOT_LOCALE)},
{Locale.ENGLISH, Arrays.asList(Locale.ENGLISH, LocaleUtils.ROOT_LOCALE)},
{Locale.US, Arrays.asList(Locale.US, Locale.ENGLISH, LocaleUtils.ROOT_LOCALE)},
{new Locale("en", "US", "xxx"), Arrays.asList(
new Locale("en", "US", "xxx"), Locale.US, Locale.ENGLISH, LocaleUtils.ROOT_LOCALE)
},
};
}

@Test(dataProvider = "getCandidateLocalesData")
@Test(dataProvider = "getCandidateLocalesData", dataProviderClass = LocaleUtilsTestData.class)
public void testGetCandidateLocales(Locale locale, List<Locale> expected) {
final List<Locale> actual = LocaleUtils.getCandidateLocales(locale);
assertEquals(actual, expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example;

import org.testng.annotations.DataProvider;

import java.util.Arrays;
import java.util.Locale;

/**
* @author Ivan Khalopik
* @since 8.0
*/
public class LocaleUtilsTestData {

@DataProvider(name = "getCandidateLocalesData", parallel = true)
public static Object[][] getCandidateLocalesData() {
return new Object[][]{
{null, Arrays.asList(LocaleUtils.ROOT_LOCALE)},
{LocaleUtils.ROOT_LOCALE, Arrays.asList(LocaleUtils.ROOT_LOCALE)},
{ Locale.ENGLISH, Arrays.asList(Locale.ENGLISH, LocaleUtils.ROOT_LOCALE)},
{Locale.US, Arrays.asList(Locale.US, Locale.ENGLISH, LocaleUtils.ROOT_LOCALE)},
{new Locale("en", "US", "xxx"), Arrays.asList(
new Locale("en", "US", "xxx"), Locale.US, Locale.ENGLISH, LocaleUtils.ROOT_LOCALE)
},
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import javax.sql.DataSource;
import java.sql.SQLException;

/**
* @author Ivan Khalopik
* @since 8.0
*/
public class ParameterizedTest extends Assert {
private DataSource dataSource;

@Parameters({"driver", "url", "username", "password"})
@BeforeClass
public void setUpDataSource(String driver, String url, @Optional("sa") String username, @Optional String password) {
dataSource = null;
}

@Test
public void testOptionalData() throws SQLException {
dataSource.getConnection();
// do some staff
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example;

import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

/**
* @author Ivan Khalopik
* @since 8.0
*/
public class PrioritiesTest extends Assert {
private boolean firstTestExecuted;

@BeforeClass
public void setUp() throws Exception {
firstTestExecuted = false;
}

@Test(priority = 0)
public void first() {
assertFalse(firstTestExecuted);
firstTestExecuted = true;
}

@Test(priority = 1)
public void second() {
assertTrue(firstTestExecuted);
}
}
43 changes: 43 additions & 0 deletions testing/testing-testng/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
~ Copyright (c) 2008-2011 Ivan Khalopik.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test suite" parallel="classes" thread-count="10">
<test name="Default tests" verbose="1" annotations="JDK" thread-count="10" parallel="classes">
<parameter name="driver" value=""/>
<groups>
<run>
<exclude name="integration"/>
</run>
</groups>

<packages>
<package name="com.example.*"/>
</packages>
</test>

<test name="Integration tests" annotations="JDK">
<groups>
<run>
<include name="integration"/>
</run>
</groups>

<packages>
<package name="com.example.*"/>
</packages>
</test>
</suite>

0 comments on commit a994693

Please sign in to comment.