我正在尝试创建运行测试所需的字符串数组。这就是我的做法。
TEST(ParseTest, UnknownType) {
String test_strings[] = {
String("X 1024\n"),
String("AB 1024\n")
};
int test_strings_size = sizeof(test_strings) / sizeof(test_strings[0]);
for (int idx = 0; idx < test_strings_size; idx++) {
Transaction transaction;
String transaction_type = test_strings[idx];
EXPECT_THROW(transaction.parse(transaction_type), ParseError);
}
}
但是当我在谷歌测试框架中运行它时,我收到以下错误:
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from ParseTest
[ RUN ] ParseTest.UnknownRequestType
tests/transaction.cpp:20: Failure
Expected: transaction.parse(transaction_type) throws an exception of type ParseError.
Actual: it throws nothing.
[ FAILED ] ParseTest.UnknownRequestType (0 ms)
[----------] 1 test from ParseTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] ParseTest.UnknownRequestType
1 FAILED TEST
当这应该实际运行两个测试用例时,它只会抱怨一个。我错过了什么吗?
答案 0 :(得分:2)
Here is some clarification:
You are actually running one test case, see the following definition:
select f_Shipmentnumber,f_ProviderID,f_ShipmentType,Max(f_date ) from t_shipment shipment
join t_Pilot pilot on pilot.f_PilotID=shipment.f_Pilot_ID
where pilot.f_ProviderID='12' and shipment.f_ShipmentType=2
and shipment.f_date > DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
group by f_Shipmentnumber,f_ProviderID,f_ShipmentType
So in the test result when it says "1 test from 1 test case ran", 'test' refers to your TestName field (in your case UnknownType) and test case refers obviously to 'test case' (ParseTest). It doesn't matter how many 'ASSERTions' or 'EXPECTations' you set inside a specific test. It will be eventually reported as one test.
So if you have
TEST(TestCase, TestName)
it will be reported as: 2 tests from 1 test case ran
So, assuming that "X 1024" is the one that will cause the exception, I suspect that the result of "AB 1024" (no exception) is the one eventually reported.
答案 1 :(得分:2)
I would write a value parameterized test to get more convenient test results.
Example:
import os
from kombu import Exchange, Queue
BROKER_URL = 'amqp://xxxx:xxxx@broker-domain.com:5672//'
CELERY_RESULT_BACKEND = "cache"
CELERY_CACHE_BACKEND = 'memcached://xxxxxx:11211'
CELERY_DEFAULT_QUEUE = 'default'
CELERY_DEFAULT_EXCHANGE_TYPE = 'topic'
CELERY_DEFAULT_ROUTING_KEY = 'default'
CELERY_QUEUES = (
Queue('default', Exchange('default'), routing_key='default'),
Queue('estimate_geometry', Exchange('estimate_geometry'), routing_key='tasks.estimate_geometry'),
Queue('segment_image', Exchange('segment_image'), routing_key='tasks.segment_image'),
Queue('geometry_feature', Exchange('geometry_feature'), routing_key='tasks.geometry_feature'),
)
CELERY_ROUTES = {
'tasks.estimate_geometry': {
'queue': 'estimate_geometry',
'routing_key': 'tasks.estimate_geometry',
},
'tasks.segment_image': {
'queue': 'segment_image',
'routing_key': 'tasks.segment_image',
},
'tasks.geometry_feature': {
'queue': 'geometry_feature',
'routing_key': 'tasks.geometry_feature',
},
}
BROKER_HEARTBEAT = 10