I use httpClient to do interface testing process, encountered a request system resources interface. If the version number is null, the system will obtain the latest resource information. If the version number is null, the system will update the local cache data if the version number is not updated. I’ve written a method that will save the version number for download on the first request, and pass it in as an argument on the second request to see if it returns nothing. A problem with jsonObject was found in the first request that null arguments were passed without arguments. If the value of jsonObject is null during the put method, the item will be hidden, so it will disappear from the JSON data.

Put your own code here:

/** * Obtain system static resources ** Obtain each version number for the first time, and use the version number ** @ for the second timereturn
	 */
	public JSONObject getResource() {
		JSONObject response = null;
		String url = urls.getString("static_config");
		JSONObject args = getParams(token);
		args.put("audio_country"."");
		args.put("audio_label"."");
		args.put("game_user_number"."");
		args.put("banner"."");
		args.put("video_open_time"."");
		args.put("tip"."");
		args.put("objective", objectiveVersion);
		args.put("startup_page", startupVersion);
		args.put("game", gameVersion);
		args.put("app", appVersion);
		args.put("gift", giftVersion);
		args.put("app_media_config", videoVersion);
		HttpGet httpGet = getHttpGet(url, args);
		output(args.size());
		response = getHttpResponseEntityByJson(httpGet);
		// output(response);
		if (response.containsKey("dataInfo") && objectiveVersion.isEmpty()) {
			JSONObject dataInfo = response.getJSONObject("dataInfo");
			objectiveVersion = dataInfo.getJSONObject("objective").getString("version");
			startupVersion = dataInfo.getJSONObject("startup_page").getString("version");
			gameVersion = dataInfo.getJSONObject("game").getString("version");
			appVersion = dataInfo.getJSONObject("app").getString("version");
			giftVersion = dataInfo.getJSONObject("gift").getString("version");
			videoVersion = dataInfo.getJSONObject("video_open_time").getString("version");
		}
		return response;
	}
Copy the code

When initializing several version numbers, the default value is null because it is a string member variable, causing no data to be requested. Change the initialization value to “” “. Here is the code to initialize the member variable.

public String objectiveVersion = ""; // Destination page Version Public String startupVersion =""; // Startup page version public String gameVersion =""; // Game version public String appVersion =""; // App update configuration version number Public String giftVersion =""; // Gift version public String videoVersion =""; // Video version numberCopy the code

Selected articles from previous issues

  1. Java one line of code to print a heart
  2. Linux performance monitoring software Netdata Chinese version
  3. Interface Test Code Coverage (JACOCO) solution sharing
  4. Performance testing framework
  5. How to perform performance tests on a Linux command line interface
  6. Graphic HTTP brain map
  7. Programming thinking for everyone
  8. JVM command brain map for testing
  9. Format the JSON data for output to the console
  10. How do I test a probabilistic business interface
  11. “Double flower” BUG test sharing
  12. Automatically turn the Swagger document into test code

Map of official Account☢ ️~ FunTester together