我想测试LiveData的值。此LiveData的值依赖于ViewModel中的另一个LiveData。当我运行应用程序时,UI正常工作。但是,当我创建单元测试来测试依赖的LiveData时,测试总是失败,并显示一个AssertionError,指出该值始终为null。 我的ViewModel中有以下LiveData。 class MovieViewModel @ViewModelInject constructor(
private val movieRepository: MovieRepository
) : ViewModel() {
private val stat
当我在视图模型中添加coroutine ()时,代码的其余部分将不会被执行。
这是我的演示代码:
class SimpleViewModel : ViewModel(), CoroutineScope {
override val coroutineContext: CoroutineContext
get() = Dispatchers.Unconfined
var data = 0
fun doSomething() {
launch {
delay(1000)
data = 1
我的粘贴命令在正常执行过程中似乎有效,但是在单元测试中,CanExecute方法总是返回false。
代码:
public class ViewModel
{
public CommandBindingCollection CommandBindings { get; set; }
public ICommand PasteCommand { get; set; }
public ViewModel()
{
CommandBinding pasteBinding
= new CommandBinding(Applica
我有一个Action,如下所示:
public ActionResult SaveAndExit()
{
ViewModel1 viewModel = new ViewModel1();
return View("Index", viewModel);
}
在单元测试中,我想检查viewModel中的视图Reg是否为空。有什么建议吗?
测试:
//act
var result = controller.SaveAndExit(viewModel) as ViewResult;
//assert
//Assert.IsNotNull(!result.Model
我已经安装了最新版本的ReSharper,我正在尝试为我的MVC控制器编写一个单元测试。我需要单元测试:
确保传递给视图的ViewModel是正确的类型。
下面是我目前的情况:
public void Create_HasCorrectViewModelType()
{
// arrange
var controller = new DraftController(_draftFacade);
// act
var viewResult = controller.Create() as ViewResult;
var viewModel = viewRe
嘿,所以我运行的单元测试我的‘注销’功能,并收到一个AssertionError,我不明白为什么它存在。
下面是错误(为了提高可读性而减少响应数据):
self.assertIn(b'Logged out', response.data)
AssertionError: b'Logged out' not found in b'<!DOCTYPE html>
...
<li>Logged Out </li>
...
我希望这不会返回一个AssertionError,因为在响应数据中可以找到文本“注销”。
编辑:这是我的