Main方法运行无错,单元测试出错的问题

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Maskkiss/article/details/84976404

一、前言

       本人在代码中打了不少中文注释,在用Main方法简单测试后,准备做单元测试,结果单元测试出现乱码报错,虽然不是乱码的问题,但对于新手来说可能不太明白。现在把经验贴出来供大家分享,避免遇坑。

二、问题截图

三、问题分析      

       我当时简单看了一下,发现第一个报错有乱码,就好意是文件编码的问题。但查看了项目的配置参数,发现并没有任何不恰当的配置。再次运行了一次,发现错误中的第二行有个提示,是在执行groovy-eclipse编译时失败的。于是去查看别的正常项目的pom配置,发现少了一个插件。造成MAVEN编译打包的时候出现很多问题,只需要加上这个插件就可以解决了。

           <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerId>groovy-eclipse-compiler</compilerId>
                    <verbose>true</verbose>
                    <fork>true</fork>
                    <compilerArguments>
                        <javaAgentClass>lombok.launch.Agent</javaAgentClass>
                    </compilerArguments>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-compiler</artifactId>
                        <version>2.9.1-01</version>
                    </dependency>
                    <dependency>
                        <groupId>org.codehaus.groovy</groupId>
                        <artifactId>groovy-eclipse-batch</artifactId>
                        <version>2.3.7-01</version>
                    </dependency>
                    <dependency>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                        <version>1.18.4</version>
                    </dependency>
                </dependencies>
            </plugin>

四、注意事项

       如果source和target这两个版本的配置不对的话,可能会出现不支持diamond的问题。 

 

展开阅读全文

调试无错,运行出错,哪位大神给看看...

12-16

代码如下:rn#include "stdafx.h"rn#include rn#include rnusing namespace std ;rnrn#define max 30000rnconst int n = 5 ; rnrntypedef struct PCBrnrn string id ;rn int arrival ;rn int service ;rn int flag ; //标识符:为-1时表示还未进入过队列,为0时表示在队列中,为1时表示已被打印出来rn course ;rnrncourse a[ n ] ;rnPCB note[ n ] ;rnrnvoid putin() //输入函数rnrn int i = 0 ;rn for ( i = 0 ; i < n ; i++ ) //输入进程rn rn cout << "进程" << i + 1 << "的id:" ;rn cin >> a[ i ].id ;rn cout << "进程" << i + 1 << "的到达时间:" ;rn cin >> a[ i ].arrival ;rn cout << "进程" << i + 1 << "的服务时间:" ;rn cin >> a[ i ].service ;rn a[ i ].flag = -1 ;rn rn rn for ( i = 0 ; i < n ; i++ )rn rn note[ i ].id = a[ i ].id ;rn note[ i ].arrival = a[ i ].arrival ;rn note[ i ].service = a[ i ].service ;rn note[ i ].flag = a[ i ].flag ;rn rnrnrnvoid reset()rnrn int i = 0 ;rn for ( i = 0 ; i < n ; i++ )rn rn a[ i ].id = note[ i ].id ;rn a[ i ].arrival = note[ i ].arrival ;rn a[ i ].service = note[ i ].service ;rn a[ i ].flag = note[ i ].flag ;rn rnrnrn/*SPF开始*/rnrnint sort_1( course * pp , int cnt ) //将cnt个进程按到达时间排序rnrn int i , j ;rn course temp ;rnrn for ( i = 0 ; i < cnt - 1 ; i++ )rn rn for ( j = 0 ; j < cnt - i ; j++ )rn rn if ( pp[ j ].arrival > pp[ j + 1 ].arrival )rn rn temp = pp[ j ] ;rn pp[ j ] = pp[ j + 1 ] ;rn pp[ j + 1 ] = temp ;rn rn rn rnrn int k = 0 ;rn if ( cnt > 1 )rn rn i = 1 ;rn while ( pp[ 0 ].arrival == pp[ i ].arrival )rn rn k++ ;rn i++ ;rn rn rnrn return k ;rnrnrncourse sort_2( course * pp , int cnt ) //按执行时间将进程排序rnrn int i , j ;rn course temp ;rnrn for ( i = 0 ; i < cnt - 1 ; i++ )rn rn for ( j = 0 ; j < cnt - i ; j++ )rn rn if ( pp[ j ].service > pp[ j + 1 ].service )rn rn temp = pp[ j ] ;rn pp[ j ] = pp[ j + 1 ] ;rn pp[ j + 1 ] = temp ;rn rn rn rnrn return pp[ 0 ] ;rnrnrnint count_1()rnrn int i = 0 ;rn int c = 0 ;rn for ( i = 0 ; i < n ; i++ )rn rn if ( a[ i ].flag == 1 )rn c++ ;rn rn return c ;rnrnrnvoid SPF()rnrn int i = 0 , j = 0 ;rn int now = 0 ;rnrn cout << "SPF :" ;rn while ( count_1() != n )rn rnstart :rn int i = 0 , j = 0 ; rn course * pp = new course[ n - count_1() ] ;rn while ( i < n )rn rn if ( a[ i ].flag != 1 )rn rn pp[ j ] = a[ i ] ;rn i++ ;rn j++ ;rn rn elsern i++ ;rn rn int num ;rn num = sort_1( pp , j ) ;rn if ( num == 0 )rn rn cout << pp[ 0 ].id << " " ;rn rn elsern rn sort_2( pp , num + 1 ) ;rn cout << pp[ 0 ].id << " " ;rn rn int record ;rn for ( int tmpi = 0 ; tmpi < n ; tmpi++ )rn rn if ( a[ tmpi ].id == pp[ 0 ].id )rn rn record = tmpi ;rn break ;rn rn rn a[ record ].flag = 1 ;rn now = pp[ 0 ].arrival + pp[ 0 ].service ;rn while ( n - count_1() )rn rn i = 0 ;rn j = 0 ;rn while ( i < n )rn rn if ( a[ i ].flag != 1 )rn rn pp[ j ] = a[ i ] ;rn i++ ;rn j++ ;rn rn elsern i++ ;rn rn sort_2( pp , j ) ;rn if ( pp[ 0 ].arrival <= now )rn rn cout << pp[ 0 ].id << " " ;rn now = now + pp[ 0 ].service ;rn for ( int tmpi = 0 ; tmpi < n ; tmpi++ )rn rn if ( a[ tmpi ].id == pp[ 0 ].id )rn rn record = tmpi ;rn break ;rn rn rn a[ record ].flag = 1 ;rn rn elsern rn i = 1 ;rn while ( i <= j )rn rn if ( pp[ i ].arrival <= now )rn rn cout << pp[ i ].id << " " ;rn now = now + pp[ i ].service ;rn for ( int k = 0 ; k < n ; k++ )rn rn if ( a[ k ].id == pp[ i ].id )rn record = k ;rn rn a[ record ].flag = 1 ;rn break ;rn rn i++ ;rn rn if ( i == j + 1 )rn goto start ;rn rn rn rn cout << endl ;rnrn return ;rnrnrn/*SPF结束*/rn底下main函数直接调用SPF就好了.rn但每次运行都会出错,要求联机检查问题或是关闭程序或是调试程序的...rn然后调试出来每一步又是没错的,结果也能够出来..[img=https://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/onion/19.gif][/img]rn求大神指点... 论坛

没有更多推荐了,返回首页