我已将我的java项目(使用黄瓜框架构建)转换为Maven Project。 我无法使用Sure Fire插件,因为我的文件夹结构不是这种格式" src / test / java"
我的文件夹结构是testng xml,包含了yellow runner文件的信息,现在我的目标是在jenkins中触发这个testng xml。
我知道从命令提示符执行testng xml,但要做到这一点,我们需要有lib文件夹。由于我使用Maven,我没有本地lib文件夹。 有人可以建议,在这种情况下该怎么办? (不想更改文件夹结构)
提前致谢
答案 0 :(得分:2)
首先通过添加为您的CLASSPATH引入所需的依赖项
将 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="deepak.com.androidnotification">
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="deepak.com.androidnotification.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="deepak.com.androidnotification.NotificationService"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
</application>
</manifest>
import android.app.Notification;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.support.v4.content.LocalBroadcastManager;
import java.io.ByteArrayOutputStream;
public class NotificationService extends NotificationListenerService {
Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
String pack = sbn.getPackageName();
String ticker ="";
if(sbn.getNotification().tickerText !=null) {
ticker = sbn.getNotification().tickerText.toString();
}
Bundle extras = sbn.getNotification().extras;
String title = extras.getString("android.title");
String text = extras.getCharSequence("android.text").toString();
int id1 = extras.getInt(Notification.EXTRA_SMALL_ICON);
Log.i("Package",pack);
Log.i("Ticker",ticker);
Log.i("Title",title);
Log.i("Text",text);
Intent msgrcv = new Intent("Msg");
msgrcv.putExtra("package", pack);
msgrcv.putExtra("ticker", ticker);
msgrcv.putExtra("title", title);
msgrcv.putExtra("text", text);
LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
Log.i("Msg","Notification Removed");
}
}
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by Deepak on 8/30/2017.
*/
public class CustomListAdapter extends BaseAdapter {
int mResource;
ArrayList<Data> arrayList;
Context context;
public CustomListAdapter(Context context,int resource, ArrayList<Data> arrayList) {
this.context = context;
this.arrayList = arrayList;
this.mResource=resource;
}
@Override
public int getCount() {
return arrayList.size();
}
@Override
public Object getItem(int position) {
return arrayList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Data data = (Data) getItem(position);
LayoutInflater inflater =LayoutInflater.from(context);
convertView=inflater.inflate(mResource,parent,false);
TextView textView=(TextView)convertView.findViewById(R.id.textView);
TextView textView1=(TextView)convertView.findViewById(R.id.textView2);
TextView textView2=(TextView)convertView.findViewById(R.id.textView3);
textView.setText(data.getName());
textView1.setText(data.getPack());
textView2.setText(data.getText());
return convertView;
}
}
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.widget.ListView;
import java.util.ArrayList;
public class MainActivity extends Activity {
ListView listView;
ArrayList<Data> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView)findViewById(R.id.list) ;
LocalBroadcastManager.getInstance(this).registerReceiver(onNotice, new IntentFilter("Msg"));
}
private BroadcastReceiver onNotice= new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String title = intent.getStringExtra("title");
String pack= intent.getStringExtra("package");
String text = intent.getStringExtra("text");
Log.d("Title",title);
Data data=new Data();
data.setName(title);
data.setPack(pack);
data.setText(text);
list=new ArrayList<Data>();
list.add(data);
listView.setAdapter(new CustomListAdapter(MainActivity.this,R.layout.list_view,list));
}
};
}
public class Data {
private String name;
private String pack;
private String text;
public Data() {
}
public Data(String name, String pack, String text) {
this.name = name;
this.pack = pack;
this.text = text;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPack() {
return pack;
}
public void setPack(String pack) {
this.pack = pack;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="26dp"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_alignStart="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="TextView"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:id="@+id/list"
android:layout_height="wrap_content"/>
</RelativeLayout>
条目放入您的pom文件中。
简而言之,您需要添加至少以下的
<dependency>
现在添加以下条目以告诉Maven测试类所在的位置以及测试资源所在的位置。
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
<exclusions>
<!-- ignoring older version of testng -->
<exclusion>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<!-- Remove the scope tag, if you have some TestNG listener code residing in src/main/java -->
<scope>test</scope>
</dependency>
有关如何调整surefire插件行为的详细信息,请参阅here。