Reworked tests
This commit is contained in:
parent
c8fe28cda9
commit
75b33ba6d6
7 changed files with 49 additions and 42 deletions
|
@ -3,18 +3,16 @@ package com.example;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
class ExampleTest {
|
class ExamplesTest {
|
||||||
public static void main(String[] args) {
|
private final ExamplesLib example = new ExamplesLib();
|
||||||
new ExampleTest().verifyHello();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFail() {
|
void foo() {
|
||||||
Assert.fail("failed");
|
Assert.assertNotEquals(example.getMessage(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void verifyHello() {
|
void verifyHello() {
|
||||||
Assert.assertTrue(true);
|
Assert.assertEquals(example.getMessage(), "Hello World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2023 the original author or authors.
|
* Copyright 2023-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -50,7 +50,7 @@ public class TestNgOperationBuild extends Project {
|
||||||
.include(dependency("org.testng", "testng", version(7, 9, 0)))
|
.include(dependency("org.testng", "testng", version(7, 9, 0)))
|
||||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
|
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
|
||||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
|
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)))
|
||||||
.include(dependency("org.assertj", "assertj-core", version(3, 24, 2)));
|
.include(dependency("org.assertj", "assertj-core", version(3, 25, 2)));
|
||||||
|
|
||||||
javadocOperation()
|
javadocOperation()
|
||||||
.javadocOptions()
|
.javadocOptions()
|
||||||
|
|
|
@ -16,27 +16,15 @@
|
||||||
|
|
||||||
package rife.bld.extension;
|
package rife.bld.extension;
|
||||||
|
|
||||||
import org.testng.Assert;
|
|
||||||
import org.testng.annotations.Test;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the TestNgSimpleTest class.
|
* Implements the TestNgExample class.
|
||||||
*
|
*
|
||||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
class TestNgSimpleTest {
|
@SuppressWarnings("PMD.TestClassWithoutTestCases")
|
||||||
public static void main(String[] args) {
|
class TestNgExample {
|
||||||
new TestNgSimpleTest().verifyHello();
|
public String getMessage() {
|
||||||
}
|
return "Hello World!";
|
||||||
|
|
||||||
@Test
|
|
||||||
void testFail() {
|
|
||||||
Assert.fail("failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void verifyHello() {
|
|
||||||
Assert.assertTrue(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,18 +20,21 @@ import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements the TestNgSimpleTest class.
|
* Implements the TestNgExampleTest class.
|
||||||
*
|
*
|
||||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
class TestNgSimple2Test {
|
class TestNgExampleTest {
|
||||||
public static void main(String[] args) {
|
private final TestNgExample example = new TestNgExample();
|
||||||
new TestNgSimple2Test().verifyHello();
|
|
||||||
|
@Test
|
||||||
|
void foo() {
|
||||||
|
Assert.assertEquals(example.getMessage(), "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void verifyHello() {
|
void verifyHello() {
|
||||||
Assert.assertTrue(true);
|
Assert.assertEquals(example.getMessage(), "Hello World!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2023 the original author or authors.
|
* Copyright 2023-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -85,7 +85,7 @@ class TestNgOperationTest {
|
||||||
void testExecute() {
|
void testExecute() {
|
||||||
assertThatThrownBy(() ->
|
assertThatThrownBy(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.testClass("rife.bld.extension.TestNgSimpleTest")
|
.testClass("rife.bld.extension.TestNgExampleTest")
|
||||||
.execute())
|
.execute())
|
||||||
.as("with testClass").isInstanceOf(ExitStatusException.class);
|
.as("with testClass").isInstanceOf(ExitStatusException.class);
|
||||||
|
|
||||||
|
@ -97,8 +97,8 @@ class TestNgOperationTest {
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.testClass("rife.bld.extension.TestNgSimpleTest")
|
.testClass("rife.bld.extension.TestNgExampleTest")
|
||||||
.methods("rife.bld.extension.TestNgSimpleTest.verifyHello")
|
.methods("rife.bld.extension.TestNgExampleTest.verifyHello")
|
||||||
.execute())
|
.execute())
|
||||||
.as("with methods").doesNotThrowAnyException();
|
.as("with methods").doesNotThrowAnyException();
|
||||||
|
|
||||||
|
@ -110,14 +110,14 @@ class TestNgOperationTest {
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.suites("src/test/resources/testng3.xml")
|
.suites("src/test/resources/testng2.xml")
|
||||||
.log(2)
|
.log(2)
|
||||||
.execute())
|
.execute())
|
||||||
.as("suite 3").doesNotThrowAnyException();
|
.as("suite 2 - log ").doesNotThrowAnyException();
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.suites("src/test/resources/testng3.xml")
|
.suites("src/test/resources/testng2.xml")
|
||||||
.testClasspath("lib/test/*", "build/main", "build/test")
|
.testClasspath("lib/test/*", "build/main", "build/test")
|
||||||
.log(2)
|
.log(2)
|
||||||
.execute())
|
.execute())
|
||||||
|
@ -125,7 +125,7 @@ class TestNgOperationTest {
|
||||||
|
|
||||||
assertThatCode(() ->
|
assertThatCode(() ->
|
||||||
new TestNgOperation().fromProject(new Project())
|
new TestNgOperation().fromProject(new Project())
|
||||||
.suites("src/test/resources/testng3.xml")
|
.suites("src/test/resources/testng2.xml")
|
||||||
.testClasspath(List.of("lib/test/*", "build/main", "build/test"))
|
.testClasspath(List.of("lib/test/*", "build/main", "build/test"))
|
||||||
.log(2)
|
.log(2)
|
||||||
.execute())
|
.execute())
|
||||||
|
@ -315,6 +315,15 @@ class TestNgOperationTest {
|
||||||
assertThat(op.options.get("-testrunfactory")).isEqualTo(FOO);
|
assertThat(op.options.get("-testrunfactory")).isEqualTo(FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testShareThreadPoolForDataProviders() {
|
||||||
|
var op = new TestNgOperation().shareThreadPoolForDataProviders(true);
|
||||||
|
assertThat(op.options.get("-shareThreadPoolForDataProviders")).isEqualTo("true");
|
||||||
|
|
||||||
|
op = new TestNgOperation().shareThreadPoolForDataProviders(false);
|
||||||
|
assertThat(op.options.get("-shareThreadPoolForDataProviders")).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSourceDir() {
|
void testSourceDir() {
|
||||||
var op = new TestNgOperation().sourceDir(FOO, BAR);
|
var op = new TestNgOperation().sourceDir(FOO, BAR);
|
||||||
|
@ -375,6 +384,15 @@ class TestNgOperationTest {
|
||||||
assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true");
|
assertThat(op.options.get("-usedefaultlisteners")).isEqualTo("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUseGlobalThreadPool() {
|
||||||
|
var op = new TestNgOperation().useGlobalThreadPool(true);
|
||||||
|
assertThat(op.options.get("-useGlobalThreadPool")).isEqualTo("true");
|
||||||
|
|
||||||
|
op = new TestNgOperation().useGlobalThreadPool(false);
|
||||||
|
assertThat(op.options.get("-useGlobalThreadPool")).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testVerbose() {
|
void testVerbose() {
|
||||||
var op = new TestNgOperation().log(1);
|
var op = new TestNgOperation().log(1);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<suite name="test suite 1" verbose="2">
|
<suite name="test suite 1" verbose="2">
|
||||||
<test name="simple test">
|
<test name="simple test">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="rife.bld.extension.TestNgSimpleTest"/>
|
<class name="rife.bld.extension.TestNgExample"/>
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
|
@ -2,9 +2,9 @@
|
||||||
<suite name="test suite 2" verbose="1">
|
<suite name="test suite 2" verbose="1">
|
||||||
<test name="exclude fail">
|
<test name="exclude fail">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="rife.bld.extension.TestNgExample">
|
<class name="rife.bld.extension.TestNgExampleTest">
|
||||||
<methods>
|
<methods>
|
||||||
<exclude name="testFail"/>
|
<exclude name="foo"/>
|
||||||
</methods>
|
</methods>
|
||||||
</class>
|
</class>
|
||||||
</classes>
|
</classes>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue