Skip to content

Commit ff6d76a

Browse files
committed
Added smoke tests for Functions.
This commit adds two simple smoke tests for Functions.
1 parent 50feba3 commit ff6d76a

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

smoke-tests/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ android {
6565
"src/combined/java",
6666
"src/database/java",
6767
"src/firestore/java",
68+
"src/functions/java",
6869
"src/storage/java",
6970
]
7071
}
@@ -97,6 +98,7 @@ dependencies {
9798
combinedImplementation "com.google.firebase:firebase-auth"
9899
combinedImplementation "com.google.firebase:firebase-database"
99100
combinedImplementation "com.google.firebase:firebase-firestore"
101+
combinedImplementation "com.google.firebase:firebase-functions"
100102
combinedImplementation "com.google.firebase:firebase-storage"
101103

102104
// Database

smoke-tests/src/combined/java/com/google/firebase/testing/combined/AllTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.firebase.testing.database.DatabaseTest;
1818
import com.google.firebase.testing.firestore.FirestoreTest;
19+
import com.google.firebase.testing.functions.FunctionsTest;
1920
import com.google.firebase.testing.storage.StorageTest;
2021
import org.junit.runner.RunWith;
2122
import org.junit.runners.Suite;
@@ -24,5 +25,5 @@
2425
* A test suite combining the individual product flavors.
2526
*/
2627
@RunWith(Suite.class)
27-
@Suite.SuiteClasses({DatabaseTest.class, FirestoreTest.class, StorageTest.class})
28+
@Suite.SuiteClasses({DatabaseTest.class, FirestoreTest.class, FunctionsTest.class, StorageTest.class})
2829
public final class AllTests {}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2018 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.testing.functions;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import android.app.Activity;
20+
import androidx.test.rule.ActivityTestRule;
21+
import androidx.test.runner.AndroidJUnit4;
22+
import com.google.firebase.functions.FirebaseFunctions;
23+
import com.google.firebase.functions.FirebaseFunctionsException;
24+
import com.google.firebase.functions.HttpsCallableResult;
25+
import com.google.firebase.testing.common.Tasks2;
26+
import java.util.HashMap;
27+
import org.junit.Rule;
28+
import org.junit.Test;
29+
import org.junit.runner.RunWith;
30+
31+
/** Functions smoke tests. */
32+
@RunWith(AndroidJUnit4.class)
33+
public final class FunctionsTest {
34+
35+
@Rule public final ActivityTestRule<Activity> activity = new ActivityTestRule<>(Activity.class);
36+
37+
@Test
38+
public void callFakeFunctionShouldFail() throws Exception {
39+
FirebaseFunctions functions = FirebaseFunctions.getInstance();
40+
Task<HttpsCallableResult> task = functions.getHttpsCallable("clearlyFake31").call();
41+
Tasks2.waitForFailure(task);
42+
}
43+
44+
@Test
45+
@SuppressWarnings("unchecked")
46+
public void callAddNumbersShouldReturnResult() throws Exception {
47+
FirebaseFunctions functions = FirebaseFunctions.getInstance();
48+
HashMap<String, Object> data = new HashMap<>();
49+
data.put("firstNumber", 13);
50+
data.put("secondNumber", 17);
51+
52+
Task<HttpsCallableResult> task = functions.getHttpsCallable("addNumbers").call(data);
53+
HttpsCallableResult result = Tasks2.waitForSuccess(task);
54+
HashMap<String, Object> map = (HashMap<String, Object>) result.getData();
55+
56+
assertThat(map.get("operationResult")).isEqualTo(30);
57+
}
58+
}

0 commit comments

Comments
 (0)