NUnit is not showing Debug messages in its window - visual-studio-2010

I'm using NUnit 262 and VS 2010.
This code should show messages writen with Debug.Writeline in the NUnit window, but it doen't.
The code:
public interface ILongRunningLibrary {
string RunForALongTime(int interval);
}
public class LongRunningLibrary : ILongRunningLibrary {
public string RunForALongTime(int interval) {
var timeToWait = interval * 1000; Thread.Sleep(timeToWait);
return string.Format("Waited {0} seconds", interval);
}
}
[TestFixture]
public class MoqExamples {
private Mock<ILongRunningLibrary> _longRunningLibrary;
[SetUp]
public void SetupForTest() {
_longRunningLibrary = new Mock<ILongRunningLibrary>();
}
[Test]
public void TestLongRunningLibrary() {
const int interval = 10;
var result = _longRunningLibrary.Object.RunForALongTime(interval);
Debug.WriteLine("Return from method was '" + result + "'");
}
[TearDown]
public void TearDownAfterTest() {
}
}
I should see this in the NUnit window:
But I see this instead:

When using Console.WriteLine, you'll see the output in the Text Output tab at the bottom of the test runner. I'm not sure if Debug.WriteLine puts it there as well. Have you checked?

Related

Grid SelectionMode.MULTI is missing the header checkbox to select all for BackEndDataProvider

I am working with a new application written to version 8 (currently testing with 8.1.0.rc2).
The issue surrounds the "select all" checkbox that appears in the header of a Grid when using SelectionMode.MULTI. In particular, the problem is that the checkbox appears and operates as expected when the DataProvider implements InMemoryDataProvider, but the checkbox does not appear when the DataProvider implements BackEndDataProvider.
The following code creates two grids that differ only in whether they use InMemory or BackEnd:
public class Test {
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
private String name;
}
public class TestView extends BaseView {
public TestView() {
super("Test");
addComponent(new TestGrid(new TestDataProvider0()));
addComponent(new TestGrid(new TestDataProvider1()));
}
}
public class TestGrid extends Grid<Test> {
public TestGrid(DataProvider<Test, ?> dataProvider) {
setHeightByRows(4);
setSelectionMode(SelectionMode.MULTI);
setDataProvider(dataProvider);
addColumn(Test::getName).setCaption("Name");
}
}
public class TestDataProvider0 extends AbstractDataProvider<Test, SerializablePredicate<Test>> implements
BackEndDataProvider<Test, SerializablePredicate<Test>> {
public Stream<Test> fetch(Query<Test, SerializablePredicate<Test>> query) {
List<Test> tests = new ArrayList<>(query.getLimit());
for (int i = 0; i < query.getLimit(); i++) {
Test test = new Test();
test.setName(String.valueOf(query.getOffset() + i));
tests.add(test);
}
return tests.stream();
}
public int size(Query<Test, SerializablePredicate<Test>> query) {
return 100;
}
public void setSortOrders(List<QuerySortOrder> sortOrders) {
}
}
public class TestDataProvider1 extends AbstractDataProvider<Test, SerializablePredicate<Test>> implements
InMemoryDataProvider<Test> {
public Stream<Test> fetch(Query<Test, SerializablePredicate<Test>> query) {
List<Test> tests = new ArrayList<>(query.getLimit());
for (int i = 0; i < query.getLimit(); i++) {
Test test = new Test();
test.setName(String.valueOf(query.getOffset() + i));
tests.add(test);
}
return tests.stream();
}
public int size(Query<Test, SerializablePredicate<Test>> query) {
return 100;
}
public SerializablePredicate<Test> getFilter() {
return null;
}
public void setFilter(SerializablePredicate<Test> filter) {
}
public SerializableComparator<Test> getSortComparator() {
return null;
}
public void setSortComparator(SerializableComparator<Test> comparator) {
}
}
Here is how the grids are rendered:
Have I missed a critical step in setting up my BackEnd-based data provider/grid? The related documentation does not seem to address this issue.
Is there a known issue related to this?
Is select-all not available by design? Obviously, this could interact really badly with the concept of lazy-loading on a large data set...
MultiSelectionModelImpl has this method:
protected void updateCanSelectAll() {
switch (selectAllCheckBoxVisibility) {
case VISIBLE:
getState(false).selectAllCheckBoxVisible = true;
break;
case HIDDEN:
getState(false).selectAllCheckBoxVisible = false;
break;
case DEFAULT:
getState(false).selectAllCheckBoxVisible = getGrid()
.getDataProvider().isInMemory();
break;
default:
break;
}
}
This indicates that the default behavior for non-in-memory providers is to not show the select-all checkbox, but that this behavior can be overridden by setting the visibility to VISIBLE.
Tweaking the original code here:
public class TestGrid extends Grid<Test> {
public TestGrid(DataProvider<Test, ?> dataProvider) {
setHeightByRows(4);
MultiSelectionModel<Test> selectionModel = (MultiSelectionModel<Test>) setSelectionMode(SelectionMode.MULTI);
selectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.VISIBLE);
setDataProvider(dataProvider);
addColumn(Test::getName).setCaption("Name");
}
}
Specifically, this call is required for the checkbox to appear for data providers that implement BackEndDataProvider:
MultiSelectionModel<Test> selectionModel = (MultiSelectionModel<Test>) setSelectionMode(SelectionMode.MULTI);
selectionModel.setSelectAllCheckBoxVisibility(SelectAllCheckBoxVisibility.VISIBLE);
With this change, the select-all checkbox now appears:

I can't make a basic project run with javaexe

I created a basic program in order to see how to make javaexe run;
The program has to be a windows service and should display a icon on the taskbar, when one click in the menu item, a messageBox is displayed.
But it does not run, especially the icon is not displayed.
Do you know why?
here are my files:
the service:
package service;
/**
* Created by User on 26/10/2014.
*/
public class Exemple_ServiceManagement {
static Corps app=null;
public static boolean serviceInit (){
app=new Corps();
return true;
}
public static void serviceFinish (){
app.setEnd(true);
}
public static String[] serviceGetInfo (){
return new String[]{"mon exemple","test","pas auto",
"1"};
}
}
the core part:
public class Corps extends Thread{
public boolean isEnd() {
return isEnd;
}
public void setEnd(boolean isEnd) {
this.isEnd = isEnd;
}
public boolean isEnd=false;
/*******************************************/
public Corps()
{
start();
}
/*******************************************/
public void run(){
while (!isEnd){
try {
Thread.sleep(250);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
and the taskbar part:
public class Exemple_TaskbarManagement {
public static void taskInit() {
}
public static String[][] taskGetMenu(boolean isRightClick, int menuID) {
return new String[][]
{
{"1", "test" , "", ""},
};
}
public static void taskDoAction (boolean isRightClick, int menuID){
if (!isRightClick && menuID==1){
javax.swing.JOptionPane.showMessageDialog(null,"Menu cliqué");
}
}
public static String[] taskGetInfo (){
return new String[]
{
"JavaExe : mon exemple",
"",
"",
"",
""
};
}
}
finally, the output directory contains:
- the file "Exemple.exe" (the javaexe exe)
- the file "Exemple.jar", generated from the above sources, without manifest
- the file "Exemple.properties", here is it:
JREversion =
PersonalClasspath =
MainArgs =
MainClass =
PersonalOptions =
RunAsService =
RunType =1
ClassDirectory =
ResourceDirectory =
URL_InstallJRE =
Display_BoxInstall =
PathBrowser =
PathJRE =
my question is very simple : do you know what's going wrong?
thanks
olivier
ps : I had a look at the example files but I want to make a basic project, not take an other from somebody else, in order to understand what I do.

c# - selenium Nunit testing - how to do validation check for signup form

Hi I am trying to test this online signup form. I have created a test but I would like to do a validation check on each field,
e.g.
For Name field
driver.FindElement(By.Id("Name")).SendKeys("Clayton")
I would like to try different text/number/characters and see what goes through and what fails.
Is there any way i could do this?
please see the codes.
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
namespace SeleniumTests
{
[TestFixture]
public class loop
{
private IWebDriver driver;
private StringBuilder verificationErrors;
private string baseURL;
private bool acceptNextAlert = true;
[SetUp]
public void SetupTest()
{
driver = new FirefoxDriver();
baseURL = "http://something.com/";
verificationErrors = new StringBuilder();
}
[TearDown]
public void TeardownTest()
{
try
{
driver.Quit();
}
catch (Exception)
{
// Ignore errors if unable to close the browser
}
Assert.AreEqual("", verificationErrors.ToString());
}
[Test]
public void TheSignupTest()
{
driver.Navigate().GoToUrl(baseURL + "/Account/Login?ReturnUrl=%2f");
driver.FindElement(By.Id("UserName")).Clear();
driver.FindElement(By.Id("UserName")).SendKeys("something");
driver.FindElement(By.Id("Password")).Clear();
driver.FindElement(By.Id("Password")).SendKeys("something");
driver.FindElement(By.CssSelector("input.btn.small")).Click();
driver.FindElement(By.Id("nav2")).Click();
driver.FindElement(By.Id("upload-file")).Click();
driver.FindElement(By.Id("Name")).Clear();
driver.FindElement(By.Id("Name")).SendKeys("00");
driver.FindElement(By.Id("ReferenceNumberPrefix")).Clear();
driver.FindElement(By.Id("ReferenceNumberPrefix")).SendKeys("00");
driver.FindElement(By.Name("submit")).Click();
}
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
private bool IsAlertPresent()
{
try
{
driver.SwitchTo().Alert();
return true;
}
catch (NoAlertPresentException)
{
return false;
}
}
private string CloseAlertAndGetItsText()
{
try
{
IAlert alert = driver.SwitchTo().Alert();
string alertText = alert.Text;
if (acceptNextAlert)
{
alert.Accept();
}
else
{
alert.Dismiss();
}
return alertText;
}
finally
{
acceptNextAlert = true;
}
}
}
}
I think a good start would be to transform your test into a parameterized test and use the TestCaseAttribute.
Your test could then look like this:
[Test]
[TestCase("Clayton", "abc", true)]
[TestCase("Clayton", "def", false)]
public void TheSignupTest(string username, string password, bool isAccepted)
{
driver.Navigate().GoToUrl(baseURL + "/Account/Login?ReturnUrl=%2f");
driver.FindElement(By.Id("UserName")).Clear();
driver.FindElement(By.Id("UserName")).SendKeys(username);
driver.FindElement(By.Id("Password")).Clear();
driver.FindElement(By.Id("Password")).SendKeys(password);
driver.FindElement(By.CssSelector("input.btn.small")).Click();
driver.FindElement(By.Id("nav2")).Click();
driver.FindElement(By.Id("upload-file")).Click();
driver.FindElement(By.Id("Name")).Clear();
driver.FindElement(By.Id("Name")).SendKeys("00");
driver.FindElement(By.Id("ReferenceNumberPrefix")).Clear();
driver.FindElement(By.Id("ReferenceNumberPrefix")).SendKeys("00");
driver.FindElement(By.Name("submit")).Click();
if (isAccepted)
{
Assert.That(driver.Url, Is.EqualTo(baseURL + "/PageWhereClientIsRedirectedToAfterSuccessfulLogin"));
}
else
{
Assert.That(driver.FindElement(By.Name("ErrorBox")).Text, Is.EqualTo("Login failed"));
}
}
The test cases are defined using the TestCaseAttribute:
[TestCase("Clayton", "abc", true)]
[TestCase("Clayton", "def", false)]
So you have two test cases in your test runner.

GWT application crashes in latest Firefox versions 21 and above

We have a GWT application which crashes in Firefox versions 21 and above, including in the latest version 23.0.1. In earlier versions of Firefox and IE 9, it works fine. This is in deployed mode and not because of the GWT plugin. The situation it crashes is when there are huge number of RPC calls, may be around 300 to 400.
As the application in which it happens is fairly complex, I tried to simulate this issue with a simple prototype. I observed that my prototype crashes when the number of RPC calls reach 100000. But this scenario is very unlikely in my application where RPC calls are around 300-400 as observed using Firebug.
I am trying to find out what else I am missing in my prototype so that it also crashes with 300-400 RPC calls.
GWT version - 2.4
GXT version - 2.2.5
package com.ganesh.check.firefox.client;
public class FirefoxCrash implements EntryPoint {
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";
private final GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);
public native static void consoleLog(String text)/*-{
$wnd.console.log(text);
}-*/;
public void onModuleLoad() {
final Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();
final Label countLabel = new Label();
// We can add style names to widgets
sendButton.addStyleName("sendButton");
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
RootPanel.get("count").add(countLabel);
// Focus the cursor on the name field when the app loads
nameField.setFocus(true);
nameField.selectAll();
// Create the popup dialog box
final DialogBox dialogBox = new DialogBox();
dialogBox.setText("Remote Procedure Call");
dialogBox.setAnimationEnabled(true);
final Button closeButton = new Button("Close");
// We can set the id of a widget by accessing its Element
closeButton.getElement().setId("closeButton");
final Label textToServerLabel = new Label();
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(new HTML("<b>Sending name to the server:</b>"));
dialogVPanel.add(textToServerLabel);
dialogVPanel.add(new HTML("<br><b>Server replies:</b>"));
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
dialogVPanel.add(closeButton);
dialogBox.setWidget(dialogVPanel);
// Add a handler to close the DialogBox
closeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});
class MyHandler implements ClickHandler, KeyUpHandler {
private int resultCount = 0;
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
sendNameToServer();
}
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
private void sendNameToServer() {
// First, we validate the input.
errorLabel.setText("");
String textToServer = nameField.getText();
// Then, we send the input to the server.
textToServerLabel.setText(textToServer);
serverResponseLabel.setText("");
final int loopCount = Integer.parseInt(textToServer);
resultCount=0;
for (int i = 0; i < loopCount; i++) {
greetingService.getResult(textToServer,
new AsyncCallback<ResultBean>() {
public void onFailure(Throwable caught) {
consoleLog(caught.getMessage());
}
public void onSuccess(ResultBean result) {
//countLabel.setText(++resultCount + "");
resultCount++;
if(resultCount==loopCount){
countLabel.setText(resultCount + "");
}
consoleLog("Result returned for "+resultCount);
}
});
}
}
}
// Add a handler to send the name to the server
MyHandler handler = new MyHandler();
sendButton.addClickHandler(handler);
nameField.addKeyUpHandler(handler);
}
}
public class GreetingServiceImpl extends RemoteServiceServlet implements
GreetingService {
public ResultBean getResult(String name) {
ResultBean result = new ResultBean();
Random random = new Random();
int suffix = random.nextInt();
result.setName("Name "+suffix);
result.setAddress("Address "+suffix);
result.setZipCode(suffix);
result.setDoorNumber("Door "+suffix);
return result;
}
public class ResultBean implements Serializable {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getZipCode() {
return zipCode;
}
public void setZipCode(int zipCode) {
this.zipCode = zipCode;
}
public String getDoorNumber() {
return doorNumber;
}
public void setDoorNumber(String doorNumber) {
this.doorNumber = doorNumber;
}
private String name;
private String address;
private int zipCode;
private String doorNumber;
}

Tombstoning in Caliburn Micro

I have MainPageViewModel with Items (ObservableCollection). On this page I also have a button, that add new items to Items.
public class MainPageViewModel : Screen {
private DateTime StartActivity = DateTime.MinValue;
public ObservableCollection<ActivityViewModel> Items { get; set; }
public MainPageViewModel(INavigationService navigationService) {
this.Items = new ObservableCollection<ActivityViewModel>();
}
public void AddActivity(string activityName) {
if (this.Items.Count == 0) {
this.Items.Add(new ActivityViewModel() {
Activity = activityName,
Duration = 0
});
StartActivity = DateTime.Now;
}
else {
this.Items[this.Items.Count - 1].Duration = 10;
this.Items.Add(new ActivityViewModel() {
Activity = activityName,
Duration = 0
});
StartActivity = DateTime.Now;
}
}
}
Adding new items works perfect.
But data from Items not recovers when app activates after tombstoning. Try create StorageHandler for my ViewModel. Doesn't help. What I'm doing wrong?
public class MainPageViewModelStorage : StorageHandler<MainPageViewModel> {
public override void Configure() {
Property(x => x.Items)
.InAppSettings()
.RestoreAfterActivation();
}
}
Also try add [SurviveTombstone] for class and for property but Visual Studio don't know that attribute.
public class ActivityViewModel : PropertyChangedBase {
private string _activity;
public string Activity {
get {
return _activity;
}
set {
if (value != _activity) {
_activity = value;
NotifyOfPropertyChange(() => Activity);
}
}
}
private double _duration;
public double Duration {
get {
return _duration;
}
set {
if (value != _duration) {
_duration = value;
NotifyOfPropertyChange(() => Duration);
}
}
}
}
You should store not InAppSettings but InPhoneState.
Check with breakpoint if method Configure is called. If not - something wrong with your bootstrapper. Probably PhoneContainer.RegisterPhoneServices() is missing
Turn on catching first chance exception in Visual Studio (Ctrl+Alt+E, and put checkbox against CLR Exceptions). Probably your view model cannot be deserialized properly.

Resources