In this article, I simply share my thoughts on solving problems in the process of writing interface code and methods of conflict resolution when submitting code by giving examples, hoping to be of little help to my friends.

Code debugging

background

Recently, we have been building an interface testing framework from scratch. At present, the framework we use is Testng, which is maintained by Java language. If there is time later, I, a small vegetable in the exploratory stage, will share this content, or friends can also search on CSDN to learn the accumulation of big guys.

Here are some of the most recent achievements. The main difficulty lies in the design of the framework and the writing of common classes.(To tell you secretly, the design of the framework is not a problem, because I copied the existing framework of another department in our company, so the code debugging is mainly focused on the classes under common.)

I met several problems, I will not list one by one, now for one or two of the problems, share my ideas and methods to solve the problem.

The debug is operating

Lines of code debug

As you can see in the picture below, I happily wrote an interface that failed when executed. At this point in the console to find the error, start to find the bug trip.

1. Click the blue area to go to the corresponding line of code.

2. Debug the corresponding code line (left-click on the number of lines).

3. Perform debugging operations on the test class4. In debugging 5. An exception is found6. Troubleshoot the cause of the abnormality (you need to know the code content here, and go to the corresponding code line to find the problem)7. Solve problemsThe wrong path should be like this in order to execute successfully, but this is not canonical.

Print log

As you can see in the picture below, I happily wrote another interface, only to get 500 when I executed it.

This is an internal error, copy request URL view error.We learned from the error that the secret key was missing, so we added this key to the corresponding code. When I happily added this key to execute, another error was reported, a null pointer, as shown below:

ResponseEntity<String> authResp = RequestUtil.sendRequest(authorizationUri, HttpMethod.GET, params, null);

Copy the code

If you look at the sendRequest line, you can basically tell that one of the parameters is missing. In this case, you can print the values of authorizationUri and Params.

// Get the Authorization header

    private HttpHeaders getAuthorizationToken(String yhm, String device) {

        HttpHeaders headers = new HttpHeaders();



        String zrrdah= XmlParserUtil.getZhxx(yhm,env).getZrrdah();

        String zhxh= XmlParserUtil.getZhxx(yhm,env).getZhxh();



        Map<String, String> params = new HashMap<>();

        params.put("zrrdah", zrrdah);

        params.put("zhxh", zhxh);

        params.put("device", device);

        if(device.equals(this.webDevice))params.put("secret", webSecret);

        else params.put("secret", appSecret);



        System.out.println("params is:" + params.toString());

        System.out.println("authorizationUri is:" + authorizationUri);

        ResponseEntity<String> authResp = RequestUtil.sendRequest(authorizationUri, HttpMethod.GET, params, null);

Copy the code

When you test the class execution, you can immediately see the reason for the error on the console: secret=nullAt this time, I probably knew why I didn’t get the secret value, because there was something wrong with secret in my config.properties configuration. After modification, I finally succeeded in running through the interface.

Finally, remove the following two lines of code before submitting the code. This is for debugging only.

System.out.println("params is:" + params.toString());

System.out.println("authorizationUri is:" + authorizationUri);

Copy the code

Resolve the conflict

The background is like this, BEFORE May Day, I applied for the transfer of post, there is a method name of the original interface engineering THAT I always want to change and have not changed. Today, I had to change it, but when I pulled the code, I found a pile of red (don’t ask me why I don’t pull first and then change, ask is I forgot), as shown in the picture:You have to resolve conflicts before you can commit code.

First, find the portal to conflict resolution


Prim MergeRed is where the conflict is, because I changed this line of code, somebody else changed this line of code, green is what was added, blue is what was changed. Here, I only changed the method name, so I only need to select the red ones that I changed, click the red arrows, and click the green and blue arrows directly to complete merging the code into the middle area, and finally click Apply. Once the conflict is resolved, git pull will not report an error.Next git push, after push successful, you can view the commit record on GitLab or IDEA.

Well, that’s all for this update.


This issue of Small buried Quotations (myself)

Growing together is the best conservation. BY- Little bury me

On May 5th, I got up early in the morning and prepared to go back to Hangzhou. I felt very sad at the thought of leaving my hometown. At that time, I did not feel that I had a bright future or a promising future, but it would not be better if I did not go.

The wrong people will be separated, if not today, then someday

Good people meet good people and live good lives.

The first three years should be tough, the middle three years should be to think more than others, the last three years should be to learn (try) technology management. By decade 10, you are indispensable and trustworthy.