Skip to content

Commit 882ad8d

Browse files
authored
Merge pull request #42 from cachedjdk/unit-integration-tests
Separate integration tests from unit tests
2 parents 81acb33 + ad5bd15 commit 882ad8d

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

docs/development.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ All module-internal names are prefixed with an underscore. Such names should
7070
not be used from another module. Modules must avoid reaching into each other's
7171
internals.
7272

73+
## Testing
74+
75+
Everything should have a unit test. In this project, we avoid access to the
76+
internet and to the user's cjdk cache directory in all unit tests. Instead,
77+
temporary directories are used to mock the cache, and, where needed, a mock
78+
server is used to test downloads.
79+
80+
Unit test modules should try not to import cjdk modules other than the one
81+
under test, although sometimes this is unavoidable.
82+
83+
Actual use of the internet (including the Coursier index) and the user cache
84+
directory is limited to integration tests, which are kept separate.
85+
7386
(versioning-scheme)=
7487

7588
## Versioning

tests/test_api.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -154,37 +154,3 @@ def test_env_var_set():
154154
with f("CJDK_TEST_ENV_VAR", "testvalue"):
155155
assert os.environ["CJDK_TEST_ENV_VAR"] == "testvalue"
156156
assert "CJDK_TEST_ENV_VAR" not in os.environ
157-
158-
159-
def test_list_vendors():
160-
vendors = _api.list_vendors()
161-
assert vendors is not None
162-
assert "adoptium" in vendors
163-
assert "corretto" in vendors
164-
assert "graalvm" in vendors
165-
assert "ibm-semeru-openj9" in vendors
166-
assert "java-oracle" in vendors
167-
assert "liberica" in vendors
168-
assert "temurin" in vendors
169-
assert "zulu" in vendors
170-
171-
172-
def test_list_jdks():
173-
jdks = _api.list_jdks(cached_only=False)
174-
assert jdks is not None
175-
assert "adoptium:1.21.0.4" in jdks
176-
assert "corretto:21.0.4.7.1" in jdks
177-
assert "graalvm-community:21.0.2" in jdks
178-
assert "graalvm-java21:21.0.2" in jdks
179-
assert "liberica:22.0.2" in jdks
180-
assert "temurin:1.21.0.4" in jdks
181-
assert "zulu:8.0.362" in jdks
182-
183-
cached_jdks = _api.list_jdks()
184-
assert cached_jdks is not None
185-
assert len(cached_jdks) < len(jdks)
186-
187-
zulu_jdks = _api.list_jdks(vendor="zulu", cached_only=False)
188-
assert zulu_jdks is not None
189-
assert len(set(zulu_jdks))
190-
assert all(jdk.startswith("zulu:") for jdk in zulu_jdks)

tests/test_integration.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This file is part of cjdk.
2+
# Copyright 2022-25 Board of Regents of the University of Wisconsin System
3+
# SPDX-License-Identifier: MIT
4+
5+
from cjdk import _api
6+
7+
8+
def test_list_vendors():
9+
vendors = _api.list_vendors()
10+
assert vendors is not None
11+
assert "adoptium" in vendors
12+
assert "corretto" in vendors
13+
assert "graalvm" in vendors
14+
assert "ibm-semeru-openj9" in vendors
15+
assert "java-oracle" in vendors
16+
assert "liberica" in vendors
17+
assert "temurin" in vendors
18+
assert "zulu" in vendors
19+
20+
21+
def test_list_jdks():
22+
jdks = _api.list_jdks(cached_only=False)
23+
assert jdks is not None
24+
assert "adoptium:1.21.0.4" in jdks
25+
assert "corretto:21.0.4.7.1" in jdks
26+
assert "graalvm-community:21.0.2" in jdks
27+
assert "graalvm-java21:21.0.2" in jdks
28+
assert "liberica:22.0.2" in jdks
29+
assert "temurin:1.21.0.4" in jdks
30+
assert "zulu:8.0.362" in jdks
31+
32+
cached_jdks = _api.list_jdks()
33+
assert cached_jdks is not None
34+
assert len(cached_jdks) < len(jdks)
35+
36+
zulu_jdks = _api.list_jdks(vendor="zulu", cached_only=False)
37+
assert zulu_jdks is not None
38+
assert len(set(zulu_jdks))
39+
assert all(jdk.startswith("zulu:") for jdk in zulu_jdks)

0 commit comments

Comments
 (0)