什么是停止测试的正确方法,因为没有使用awaitillity发布任何内容

时间:2016-09-12 15:12:38

标签: java async-await awaitility

我目前正在测试中使用awaitility功能。我试图将消息发布到我的pubnub控制台。然而,由于我已经实施了取消订阅拆解,目前尚未发生这种情况。我正在为awaitility的语法挣扎。我已经有几行来向您展示我一直在做的事情。有人能指出我正确的道路吗?

import com.pubnub.api.PubnubException;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import service.PubnubService;
import static com.jayway.awaitility.Awaitility.await;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;




/**
 * Created by peterki on 07/09/2016.
 */
public class PublisherTest {

    private PubnubService service = new PubnubService();

    //Arrange method for all of the tests
    @Before
    public void setupConnection() throws PubnubException {

        // Setup Subscriber
        service.subscribe("my_channel");

        // Do nothing until the subscriber has connected.
        do{} while (!service.isConnected());

    }

    @After
    public void TeardownConnection() throws PubnubException {

        // Unsubscribe from channel after each test has completed. So that the next test isn't waiting so subscribe.
        service.unsubscribe("my_channel");

    }

    @Test
    public void testSportMessageType() throws PubnubException {


        // Publish to External Service
        service.publish("my_channel", "Hello Peter");

        //Wait till we receive the message
        await().until(); -> service.publish("my_channel"); == 1;
        await().until(() -> service.publish("my_channel", "Hello Peter")() == 1);

        // Assert the message is what we want

    }
}

0 个答案:

没有答案