8000 Update SAMPLE_FORMAT.md (#4585) · coderatgoogle/java-docs-samples@baf13e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit baf13e3

Browse files
authored
Update SAMPLE_FORMAT.md (GoogleCloudPlatform#4585)
* Require IT as prefix or suffix for most tests * Add **Preferred Dependencies** section - [x] Please **merge** this PR for me once it is approved.
1 parent ca1036d commit baf13e3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

SAMPLE_FORMAT.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* [Exception Handling]()
2323
* [Client Initialization](#client-initialization)
2424
* [Command-Line Arguments](#command-line-arguments)
25+
* [Preferred Dependencies](#preferred-dependencies)
2526
* [Modern Java](#modern-java)
2627
* [Lambdas](#lambdas)
2728
* [Streams](#streams)
@@ -77,8 +78,10 @@ correctly - it is an explicit non goal for tests to verify that API is performin
7778
Because of this, mocks for external services are strongly discouraged.
7879

7980
* Test Library: [JUnit4](https://junit.org/junit4/)
80-
* Test Runner: [Maven Failsafe plugin](https://maven.apache.org/surefire/maven-failsafe-plugin/)
81-
and [Maven Surefire plugin](https://maven.apache.org/surefire/maven-surefire-plugin/).
81+
* Test Runner: [Maven Failsafe plugin](https://maven.apache.org/surefire/maven-failsafe-plugin/)
82+
(Integration Tests) and [Maven Surefire plugin](https://maven.apache.org/surefire/maven-surefire-plugin/) (Unit Tests).
83+
84+
Most of our sample tests are Integration Tests and should be marked as such using either the Prefix or suffix `IT`.
8285

8386
As an example, the following test code shows how we test a region tag (region tags are tools Google
8487
uses to identify sections of the snippets to be highlighted in documentation) called `region_tag`:
@@ -95,7 +98,7 @@ import org.junit.runners.JUnit4;
9598
* Store region_tag in test method name, camel-cased
9699
*/
97100
@RunWith(JUnit4.class)
98-
public class SomeClassTest {
101+
public class SomeClassIT {
99102
@Test public void regionTag_shouldPass() throws Exception { }
100103

101104
@Test public void regionTag_shouldFail() throws Exception {
@@ -159,10 +162,8 @@ To run the `functions` tests (or other tests without a parent `pom.xml`), use th
159162
```
160163
cd functions
161164
find */pom.xml | xargs -I {} echo $(pwd)/{} | xargs -I {} dirname {} | xargs -I {} sh -c "cd {} && mvn clean verify"
162-
163165
```
164166

165-
166167
### Gradle Specifics
167168
#### NEEDS WORK
168169
Your `build.gradle` should have the following section:
@@ -396,6 +397,12 @@ considered an anti-pattern, and new samples should not implement them.
396397
397398
**Dataflow** samples are an exception to this guideline.
398399
400+
### Preferred Dependencies
401+
Google written dependencies are always preferred over alternatives. For example:
402+
* [Guava](https://github.com/Google/Guava) is preferred over [Apache commons lang](https://commons.apache.org/)
403+
* [GSON](https://github.com/Google/GSON) is preferred for JSON parsing.
404+
* [Google HTTP Client](https://github.com/googleapis/google-http-java-client) is preferred.
405+
399406
## Modern Java
400407
Prefer using modern idioms / language features over older styles.
401408

0 commit comments

Comments
 (0)
0