-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-22308] Support alternative unit testing styles in external applications #19529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b9d41cd
Separate out the portion of SharedSQLContext that requires a FunSuite…
nkronenfeld 0d4bd97
Fix typo in trait name
nkronenfeld 83c44f1
Add simple tests for each non-FunSuite test style
nkronenfeld e460612
Document testing possibilities
nkronenfeld 0ee2aad
Better documentation of testing procedures
nkronenfeld 802a958
Same initialization issue in SharedSparkContext as is in SharedSparkS…
nkronenfeld 4218b86
Remove documentation of testing
nkronenfeld 2d927e9
Move base versions of PlanTest and SQLTestUtils into the same file as…
nkronenfeld 38a83c0
Comment line length should be 100
nkronenfeld 241459a
Move SQLTestUtils object to the end of the file
nkronenfeld 24fc4a3
fix scalastyle error (whitespace at end of line)
nkronenfeld e4763d9
Remove extraneous curly brackets around empty PlanTest body
nkronenfeld 6c0b0d5
Remove extraneous beforeAll and brackets from SharedSQLContext
nkronenfeld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
sql/core/src/test/scala/org/apache/spark/sql/test/GenericFlatSpecSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.test | ||
|
|
||
| import org.scalatest.FlatSpec | ||
|
|
||
| /** | ||
| * The purpose of this suite is to make sure that generic FlatSpec-based scala | ||
| * tests work with a shared spark session | ||
| */ | ||
| class GenericFlatSpecSuite extends FlatSpec with SharedSparkSession { | ||
| import testImplicits._ | ||
| initializeSession() | ||
| val ds = Seq((1, 1), (2, 1), (3, 2), (4, 2), (5, 3), (6, 3), (7, 4), (8, 4)).toDS | ||
|
|
||
| "A Simple Dataset" should "have the specified number of elements" in { | ||
| assert(8 === ds.count) | ||
| } | ||
| it should "have the specified number of unique elements" in { | ||
| assert(8 === ds.distinct.count) | ||
| } | ||
| it should "have the specified number of elements in each column" in { | ||
| assert(8 === ds.select("_1").count) | ||
| assert(8 === ds.select("_2").count) | ||
| } | ||
| it should "have the correct number of distinct elements in each column" in { | ||
| assert(8 === ds.select("_1").distinct.count) | ||
| assert(4 === ds.select("_2").distinct.count) | ||
| } | ||
| } | ||
47 changes: 47 additions & 0 deletions
47
sql/core/src/test/scala/org/apache/spark/sql/test/GenericFunSpecSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.test | ||
|
|
||
| import org.scalatest.FunSpec | ||
|
|
||
| /** | ||
| * The purpose of this suite is to make sure that generic FunSpec-based scala | ||
| * tests work with a shared spark session | ||
| */ | ||
| class GenericFunSpecSuite extends FunSpec with SharedSparkSession { | ||
| import testImplicits._ | ||
| initializeSession() | ||
| val ds = Seq((1, 1), (2, 1), (3, 2), (4, 2), (5, 3), (6, 3), (7, 4), (8, 4)).toDS | ||
|
|
||
| describe("Simple Dataset") { | ||
| it("should have the specified number of elements") { | ||
| assert(8 === ds.count) | ||
| } | ||
| it("should have the specified number of unique elements") { | ||
| assert(8 === ds.distinct.count) | ||
| } | ||
| it("should have the specified number of elements in each column") { | ||
| assert(8 === ds.select("_1").count) | ||
| assert(8 === ds.select("_2").count) | ||
| } | ||
| it("should have the correct number of distinct elements in each column") { | ||
| assert(8 === ds.select("_1").distinct.count) | ||
| assert(4 === ds.select("_2").distinct.count) | ||
| } | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
sql/core/src/test/scala/org/apache/spark/sql/test/GenericWordSpecSuite.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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. | ||
| */ | ||
|
|
||
| package org.apache.spark.sql.test | ||
|
|
||
| import org.scalatest.WordSpec | ||
|
|
||
| /** | ||
| * The purpose of this suite is to make sure that generic WordSpec-based scala | ||
| * tests work with a shared spark session | ||
| */ | ||
| class GenericWordSpecSuite extends WordSpec with SharedSparkSession { | ||
| import testImplicits._ | ||
| initializeSession() | ||
| val ds = Seq((1, 1), (2, 1), (3, 2), (4, 2), (5, 3), (6, 3), (7, 4), (8, 4)).toDS | ||
|
|
||
| "A Simple Dataset" when { | ||
| "looked at as complete rows" should { | ||
| "have the specified number of elements" in { | ||
| assert(8 === ds.count) | ||
| } | ||
| "have the specified number of unique elements" in { | ||
| assert(8 === ds.distinct.count) | ||
| } | ||
| } | ||
| "refined to specific columns" should { | ||
| "have the specified number of elements in each column" in { | ||
| assert(8 === ds.select("_1").count) | ||
| assert(8 === ds.select("_2").count) | ||
| } | ||
| "have the correct number of distinct elements in each column" in { | ||
| assert(8 === ds.select("_1").distinct.count) | ||
| assert(4 === ds.select("_2").distinct.count) | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are testing tests? I get it, but I don't know if it's necessary. If FlatSpec didn't work, scalatest would hopefully catch it. If initializeSession / SharedSparkSession didn't, presumably tons of tests wouldn't work.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't totally sure about that either. I started off with the tests in another branch I wasn't going to include in the PR, just to make sure I'd done everything correctly.
I eventually came to the conclusion that they are useful. I think of it more in terms of preventing regressions; they should prevent a FunSuite dependecy creeping back in to SharedSparkSession.
For similar reasons, I should probably put similar tests in for SharedSparkContext.