Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
N notebook
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3
    • Issues 3
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Mark Stevens
  • notebook
  • Wiki
  • unit testing

unit testing · Changes

Page history
mstevens created page: unit testing authored Nov 01, 2017 by Mark Stevens's avatar Mark Stevens
Show whitespace changes
Inline Side-by-side
Showing with 20 additions and 20 deletions
+20 -20
  • unit-testing.md unit-testing.md +20 -20
  • No files found.
unit-testing.md
View page @ 2fe7f003
......@@ -2,6 +2,26 @@
### Using NanoHttpd to isolate network call testing
### Simple synchronous network call
```java
public void testSimpleEcho() throws Exception {
URL url = new URL("http://localhost:7078/echo/hello_world");
String responseContents = "";
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
java.util.Scanner s = new java.util.Scanner(in).useDelimiter("\\A");
if (s.hasNext()) {
responseContents = s.next();
}
} finally {
urlConnection.disconnect();
}
assertEquals("hello_world", responseContents );
}
```
Setup
#### Gradle
if you are only using nanohttp for testing then use testCompile, otherwise compile
......@@ -156,26 +176,6 @@ mstevens@lt-mstevens-mac2:androidTest$ tree
```
### Simple synchronous network call
```java
public void testSimpleEcho() throws Exception {
URL url = new URL("http://localhost:7078/echo/hello_world");
String responseContents = "";
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
java.util.Scanner s = new java.util.Scanner(in).useDelimiter("\\A");
if (s.hasNext()) {
responseContents = s.next();
}
} finally {
urlConnection.disconnect();
}
assertEquals("hello_world", responseContents );
}
```
### Using a Semaphore to test network responses
Semaphore is an easy way to deal with async calls. A semaphore tracks a permit count, release( ) increments the permit count, aquire( ) decrements the permit if it was non zero.
......
Clone repository
  • branch code plan
  • build and test configuration
  • build artifact versioning
  • build server instrumented testing
  • build server move
  • bzt16wifi02 releases
  • bzt18uxa02 releases
  • configuration settings and permissions
  • create a repo from cli in gitlab
  • engineering status
  • feature deployment
  • gitlab installation instructions
  • Home
  • ota update and deployment
  • qbert implementation
View All Pages