簡體   English   中英

您如何偽造vaadin會話進行集成測試?

[英]How do you fake a vaadin session for integration tests?

假設我有一個自定義注釋

@ViewScope //<-- the issue
@Qualifier
@Component
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.FIELD,ElementType.PARAMETER,ElementType.METHOD, ElementType.ANNOTATION_TYPE})
public @interface Foo { ... }

我現在想測試一種方法,該方法應該檢索帶有該批注的所有bean。

我如何在這種集成測試中偽造vaadin會話

@RunWith(SpringJUnit4ClassRunner::class)
@SpringBootTest
@WebAppConfiguration
class FooAnnotationIT{

    @Autowired(required = false) //required=false --> empty list instead of exception when none are found
    @Foo
    val foos:List<Any> = mutableListOf()

    @Test
    fun `all beans are present`(){
        assertThat(foos.size).isEqualTo(5)
    }
}

成功而不是崩潰

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'blah.blah.blah.FooAnnotationIT': Unsatisfied dependency expressed through field 'foos'
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewCache': Scope 'vaadin-ui' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton
    Caused by: java.lang.IllegalStateException: No VaadinSession bound to current thread

Karibu Testing https://github.com/mvysny/karibu-testing/tree/master/karibu-testing-v8

它具有模擬Vaadin會話的方法,它支持V8和V10 +,甚至還支持Kotlin!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM