我有一个带测试类的xml文件。这是我的testng套件xml。每个测试类,具有以下结构:
@BeforeClass
public void beforeClass(){
}
@Test(dataProvider="Mail Information")
public void mailSend(String to,String subject,String body) throws Exception{
}
@AfterClass{
}
当我错误地在AfterClass
中放置一个空对象时,测试正确失败,使用java.lang.NullPointerException
,但是不是继续进行套件的其他测试,所有其他测试都变为Skipped。
我认为他们被跳过了,因为他们的@beforeClass
被跳过了。所以我认为真正的问题是AfterClass
中的失败,以某种方式影响了套件中以下测试的BeforeClasses。
我们如何处理这个问题?
答案 0 :(得分:4)
经过很长一段时间,我找到了解决问题的方法.. 通过在套件标签中添加entryconfigfailurepolicy,并将其设置为继续,在您的套件xml文件中,这一切都消失了:
<suite name="Test-Suite" configfailurepolicy="continue">
默认情况下,参数的值为skip,如果配置失败,则导致测试跳过。
答案 1 :(得分:2)
我还没有尝试过,但根据TestNG documentation,它应该可以解决您的问题。对于每个测试方法,将alwaysRun属性设置为true。
答案 2 :(得分:0)
我尝试以“ alwaysRun = true”的方式始终在@AfterClass注释上运行该函数。尽管任何@Test都具有NullPointerException
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../core/util.dart';
class Cards extends StatelessWidget {
static const routeName = '/cards';
const Cards({Key key}) : super(key: key);
static const IconData addIcon = const IconData(62601,
fontFamily: CupertinoIcons.iconFont,
fontPackage: CupertinoIcons.iconFontPackage);
Widget _paymentCard(
String cardType,
String creditCardNumber,
int subscriptions,
Color startColor,
Color endColor,
String backgroundImage) {
return Container(
height: 200,
margin: EdgeInsets.only(left: 30, top: 30, right: 30),
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 15),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
stops: [0, 1],
colors: [
startColor,
endColor,
],
),
image: DecorationImage(
image: ExactAssetImage('assets/images/$backgroundImage.png'),
fit: BoxFit.scaleDown,
),
borderRadius: BorderRadius.all(
Radius.circular(10),
),
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 2.0,
spreadRadius: 2.0,
offset: Offset(0.0, 3.0),
),
],
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
width: 50,
child: cardType == 'mastercard'
? Image.asset('assets/images/logo-mastercard.png')
: Image.asset('assets/images/logo-visa.png'),
),
Row(
children: <Widget>[
Text(
'Subscriptions',
style: TextStyle(color: Colors.white, fontSize: 16),
),
Container(
height: 22,
width: 22,
margin: EdgeInsets.only(left: 10),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(15),
),
),
child: Text(
subscriptions.toString(),
style: TextStyle(
fontSize: 12,
fontFamily: 'SF Pro Display',
fontWeight: FontWeight.w800),
),
)
],
),
],
),
Text(
creditCardNumber,
style: TextStyle(
color: Colors.white,
fontFamily: 'Saira',
fontWeight: FontWeight.w500,
letterSpacing: 5.5),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Card holder',
style: TextStyle(
color: Colors.white54,
letterSpacing: 0.3,
fontSize: 14),
),
Text(
'Jennyy Parker',
style: TextStyle(
color: Colors.white, fontSize: 14, letterSpacing: 0.3),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Expiry',
style: TextStyle(
color: Colors.white54,
letterSpacing: 0.3,
fontSize: 14),
),
Text(
'09 / 20',
style: TextStyle(
color: Colors.white, letterSpacing: 0.3, fontSize: 14),
),
],
),
],
),
],
),
);
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
backgroundColor: CustomColors.BackgroundColor,
child: CustomScrollView(
slivers: <Widget>[
CupertinoSliverNavigationBar(
backgroundColor: Colors.white,
actionsForegroundColor: CustomColors.BlueIcon,
largeTitle: Text('My Cards'),
trailing: Icon(addIcon),
previousPageTitle: 'Dashboard',
),
SliverList(
delegate: SliverChildListDelegate(
[
_paymentCard(
'visa',
'2564 3008 4589 8790',
1,
CustomColors.CardVisaPurple,
CustomColors.CardVisaIndigo,
'card_visa_purple_bubbles'),
Container(
height: 80,
margin: EdgeInsets.symmetric(horizontal: 50),
padding: EdgeInsets.symmetric(horizontal: 30),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: CustomColors.BlueLightBorder,
blurRadius: 2.0,
spreadRadius: 2.0,
offset: Offset(0.0, 3.0),
),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset('assets/images/logo-spotify-with-text.png'),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Rs. 800',
style: TextStyle(
fontSize: 14,
letterSpacing: 1,
fontFamily: 'SF Compact Text',
fontWeight: FontWeight.w600),
),
Text(
'01 June 2019',
style: TextStyle(
fontSize: 14,
letterSpacing: 0.3,
),
)
],
)
],
),
),
Container(
height: 500,
margin: EdgeInsets.only(bottom: 50),
child: Stack(
children: <Widget>[
Positioned(
top: 10,
child: _paymentCard(
'mastercard',
'2444 3324 458 58000',
4,
CustomColors.CardMastercardGrey,
CustomColors.CardMastercardBlack,
'transparent'),
),
Positioned(
top: 70,
child: _paymentCard(
'visa',
'2444 3324 458 58000',
2,
CustomColors.CardVisaPurple2,
CustomColors.CardVisaPurple3,
'transparent'),
),
Positioned(
top: 130,
child: _paymentCard(
'mastercard',
'2444 3324 458 58000',
1,
CustomColors.CardBlueLight,
CustomColors.CardBlueDark,
'card_mastercard_starts'),
)
],
),
),
],
),
),
],
),
);
}
}