Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd59b88d

Browse files
committed
Add option to fail on errors
1 parentc0757c4 commitd59b88d

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

‎src/main/java/io/github/utplsql/api/TestRunner.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageio.github.utplsql.api;
22

3+
importio.github.utplsql.api.exception.SomeTestsFailedException;
34
importio.github.utplsql.api.reporter.DocumentationReporter;
45
importio.github.utplsql.api.reporter.Reporter;
56
importoracle.jdbc.OracleConnection;
@@ -21,6 +22,7 @@ public class TestRunner {
2122
privateList<String>testFiles =newArrayList<>();
2223
privateList<String>includeObjects =newArrayList<>();
2324
privateList<String>excludeObjects =newArrayList<>();
25+
privatebooleanfailOnErrors =false;
2426

2527
publicTestRunneraddPath(Stringpath) {
2628
this.pathList.add(path);
@@ -72,7 +74,12 @@ public TestRunner excludeObject(String obj) {
7274
returnthis;
7375
}
7476

75-
publicvoidrun(Connectionconn)throwsSQLException {
77+
publicTestRunnerfailOnErrors(booleanfailOnErrors) {
78+
this.failOnErrors =failOnErrors;
79+
returnthis;
80+
}
81+
82+
publicvoidrun(Connectionconn)throwsSomeTestsFailedException,SQLException {
7683
for (Reporterr :this.reporterList)
7784
validateReporter(conn,r);
7885

@@ -86,16 +93,23 @@ public void run(Connection conn) throws SQLException {
8693

8794
// Workaround because Oracle JDBC doesn't support passing boolean to stored procedures.
8895
StringcolorConsoleStr =Boolean.toString(this.colorConsole);
96+
StringfailOnErrors =Boolean.toString(this.failOnErrors);
8997

9098
OracleConnectionoraConn =conn.unwrap(OracleConnection.class);
9199
CallableStatementcallableStatement =null;
92100
try {
93101
callableStatement =conn.prepareCall(
94102
"BEGIN " +
95103
"ut_runner.run(" +
96-
"a_paths => ?, a_reporters => ?, a_color_console => " +colorConsoleStr +", " +
97-
"a_coverage_schemes => ?, a_source_files => ?, a_test_files => ?, " +
98-
"a_include_objects => ?, a_exclude_objects => ?); " +
104+
"a_paths => ?, " +
105+
"a_reporters => ?, " +
106+
"a_color_console => " +colorConsoleStr +", " +
107+
"a_coverage_schemes => ?, " +
108+
"a_source_files => ?, " +
109+
"a_test_files => ?, " +
110+
"a_include_objects => ?, " +
111+
"a_exclude_objects => ?, " +
112+
"a_fail_on_errors => " +failOnErrors +"); " +
99113
"END;");
100114

101115
intparamIdx =0;
@@ -142,6 +156,12 @@ public void run(Connection conn) throws SQLException {
142156
}
143157

144158
callableStatement.execute();
159+
}catch (SQLExceptione) {
160+
if (e.getErrorCode() ==SomeTestsFailedException.ERROR_CODE) {
161+
thrownewSomeTestsFailedException(e.getMessage(),e);
162+
}else {
163+
throwe;
164+
}
145165
}finally {
146166
if (callableStatement !=null)
147167
callableStatement.close();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
packageio.github.utplsql.api.exception;
2+
3+
importjava.sql.SQLException;
4+
5+
/**
6+
* Custom exception class to indicate if some tests failed.
7+
*/
8+
publicclassSomeTestsFailedExceptionextendsSQLException {
9+
10+
publicstaticfinalintERROR_CODE =20213;
11+
12+
publicSomeTestsFailedException(Stringreason,Throwablecause) {
13+
super(reason,cause);
14+
}
15+
16+
}

‎src/test/java/io/github/utplsql/api/TestRunnerTest.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
packageio.github.utplsql.api;
22

3+
importio.github.utplsql.api.exception.SomeTestsFailedException;
34
importio.github.utplsql.api.reporter.*;
45
importio.github.utplsql.api.rules.DatabaseRule;
56
importorg.junit.Assert;
@@ -32,7 +33,6 @@ public void runWithManyReporters() {
3233
try {
3334
Connectionconn =db.newConnection();
3435
newTestRunner()
35-
.addPath("ut3")
3636
.addPath(db.getUser())
3737
.addReporter(newDocumentationReporter().init(conn))
3838
.addReporter(newCoverageHTMLReporter().init(conn))
@@ -47,4 +47,19 @@ public void runWithManyReporters() {
4747
}
4848
}
4949

50+
@Test
51+
publicvoidfailOnErrors() {
52+
try {
53+
Connectionconn =db.newConnection();
54+
newTestRunner()
55+
.failOnErrors(true)
56+
.run(conn);
57+
Assert.fail();
58+
}catch (SomeTestsFailedExceptionignored) {
59+
System.out.println("Expected exception object thrown.");
60+
}catch (SQLExceptione) {
61+
Assert.fail("Wrong exception object thrown.");
62+
}
63+
}
64+
5065
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp